API

config_yourself

config_yourself.AppConfig(config_file=None, before=None, after=None, config_folder='./config')[source]

Load a sequence of resolved config file names

When using config_yourself in Flask or Django, this helper will load:

  • the "{config_folder}/defaults.yml" file,

  • a file located at os.environ.get("CONFIG_FILE", path.join(config_folder, "local.yml"))

  • a "{config_folder}/personal.yml" file, if it exists

All parameters are optional, and allow tweaking of the locations and extensions used for config files. File extensions are not required for the before and after parameters, as it will be derived from config_file, which does require an extension to be set.

Parameters
  • config_file (Optional[str]) – the path to the main config file to load, usually in the form of ./config/your-environment-name.yml. (default: os.environ.get("CONFIG_FILE", "./config/local.yml"))

  • before (Optional[list[str]]) – File names to load before config_file without (default: [‘default’])

  • after (Optional[list[str]]) – File names to apply after config_file if they exist (default: [‘personal’])

  • config_folder (Optional[str]) – Base folder path to look for files in, (default: ./config)

Returns

A Config object

Return type

Config

class config_yourself.Config(default_config, *configs, **secrets)[source]

Bases: collections.abc.Mapping, collections.abc.Hashable

A Config object

The configs supplied are merged sequentially, the resulting dict is decrypted recursively and frozen. Config objects are proxies for that resulting dict, and behave just like it

Parameters
  • default_config (dict[str,Any]) – A dictionary with default values

  • configs (List[dict[str,Any]]) – Any number of overrides to apply over default_config

  • password (str) – The password string when crypto.provider is password

  • privateKey (str) – The armored contents of the private GPG key when crypto.provider is gpg

Returns

A decrypted config file as a frozen dictionary

get(k[, d]) → D[k] if k in D, else d. d defaults to None.
items() → a set-like object providing a view on D's items
keys() → a set-like object providing a view on D's keys
values() → an object providing a view on D's values

config_yourself.load

config_yourself.load.file(pathname)[source]

returns the dict representation of yaml file at path

Parameters

path (str) – The path of the file to parse as YAML.

Returns

A dictionary of loaded values from the file

Return type

dict[str,Any]

config_yourself.load.env(prefix='CONFIG')[source]

Loads all environment variables prefixed with prefix.

For example, setting the environment variable CONFIG.override.key=”true” would set key of override to True.

Parameters

prefix (str) – The prefix to use when filtering environment variables. (default: CONFIG)

Returns

A dictionary of loaded values from the environment

Return type

dict[str,Any]

config_yourself.exceptions

exception config_yourself.exceptions.ConfigException[source]

Bases: Exception

The base Config Exception

exception config_yourself.exceptions.DecryptError(full_path, original=None)[source]

Bases: config_yourself.exceptions.ConfigException

A value could not be decrypted

exception config_yourself.exceptions.InvalidConfig(original=None, message='crypto property is not an object of key and region.')[source]

Bases: config_yourself.exceptions.ConfigException

A supplied config file was not valid