Usage

You can import and use prettyconf in your Python code:

from prettyconf import config

MY_CONFIG = config("PROJECT_MY_CONFIG")

If PROJECT_MY_CONFIG is not defined in an environment variable neither in a .env (or *.cfg) file, prettyconf will raise a UnknownConfiguration exception.

Warning

prettyconf will skip configuration files inside .zip, .egg or wheel packages.

In these cases you could define a default configuration value:

MY_CONFIG = config("PROJECT_MY_CONFIG", default="default value")

You can also use the cast argument to convert a string value into a specific value type:

DEBUG = config("DEBUG", default=False, cast=config.boolean)

The boolean cast converts strings values like On|Off, 1|0, yes|no, true|False into Python boolean True or False.

See also

Find out more about other casts or how to write your own at Casts.

Configuration files discovery

By default library will use the directory of the file where config() was called as the start directory to look for configuration files. Consider the following file structure:

project/
  settings.ini
  app/
    settings.py

If you call config() from project/app/settings.py the library will start looking for configuration files at project/app until it finds .env|*.ini|*.cfg files.

See also

This behavior is described more deeply on the RecursiveSearch loader. Loaders will help you customize how configuration discovery works. Find out more at Customizing the configuration discovery.