Functions¶
loader¶
- loader.dump_secrets(fmt='TOML', **kwargs)¶
Dump a secrets dictionary to the specified format.
Dump a secrets dictionary to the specified format, defaulting to TOML.
- Parameters
fmt (string, default="TOML") – The dump format, one of
TOML,JSON,YAML,BespON, orENV.kwargs (dict) – A dictionary of configuration variables.
- loader.generate_secret_key()¶
Generate a secret key for a Django app.
Generate a secret key for a Django app, using
django.core.management.utils.get_random_secret_key.- Returns
A random secret key.
- Return type
string
- loader.load_environment(prefix='DJANGO_ENV_')¶
Load Django configuration variables from the enviroment.
This function searches the environment for variables prepended with
prefix. Currently, this function only reliably works for string variables, but hopefully will work for other types, dictionaries, and lists in the future.- Parameters
prefix (string, default=”DJANGO_ENV_”) – Prefix for environment variables. This prefix should be prepended to all valid variable names in the environment.
- Returns
A dictionary, possibly empty, of configuration variables and values.
- Return type
dict
- loader.load_file(fn, raise_bad_format=True)¶
Attempt to load configuration variables from
fn.Attempt to load configuration variables from
fn. Iffndoes not exist or is not a recognized format, return an empty dict. RaisesImproperlyConfiguredif the file exists and does not match a recognized format unlessraise_bad_formatisFalse.- Parameters
fn (string) – Filename from which to load configuration values.
raise_bad_format (boolean, default=True) – Determine whether to raise
django.core.exceptions.ImproperlyConfiguredif the file format is not recognized. Default isTrue.
- Returns
A dictionary, possibly empty, of configuration variables and values.
- Return type
dict
- Raises
django.core.exceptions.ImproperlyConfigured – Raises an
ImproperlyConfiguredexception if the file format is not recognized andraise_bad_formatisTrue.
- loader.load_secrets(fn='.env', prefix='DJANGO_ENV_', **kwargs)¶
Load a list of configuration variables.
Return a dictionary of configuration variables, as loaded from a configuration file or the environment. Values passed in as
argsor as the value inkwargswill be used as the configuration variable’s default value if one is not found in the configuration file or environment.- Parameters
fn (string, default=".env") – Configuration filename, defaults to
.env. May be in TOML, JSON, YAML, or BespON formats. Formats will be attempted in this order.prefix (string, default=”DJANGO_ENV_”) – Prefix for environment variables. This prefix will be prepended to all variable names before searching for them in the environment.
kwargs (dict, optional) – Dictionary with configuration variables as keys and default values as values.
- Returns
A dictionary of configuration variables and their values.
- Return type
dict
- loader.main()¶
Run as script, to access
dump()functions.
- loader.merge(defaults, file, env)¶
Merge configuration from defaults, file, and environment.
- loader.validate_falsy(name, val)¶
Validate that
valis falsy.Validate that
valis falsy according to https://docs.python.org/3/library/stdtypes.html#truth-value-testing.- Parameters
val (any) – Configuration variable to validate.
- Returns
Trueifvalis falsy.- Return type
boolean
- Raises
django.core.exceptions.ImproperlyConfigured – Raises an
ImproperlyConfiguredexception on truthy values, with an error message.
- loader.validate_not_empty_string(name, val)¶
Validate that
valis not an empty string.Validate that
valis not an empty string.- Parameters
val (any) – Configuration variable to validate.
- Returns
Trueifvalis not an empty string.- Return type
boolean
- Raises
django.core.exceptions.ImproperlyConfigured – Raises an
ImproperlyConfiguredexception on empty strings, with an error message.
- loader.validate_truthy(name, val)¶
Validate that
valis truthy.Validate that
valis truthy according to https://docs.python.org/3/library/stdtypes.html#truth-value-testing.- Parameters
val (any) – Configuration variable to validate.
- Returns
Trueifvalis truthy.- Return type
boolean
- Raises
django.core.exceptions.ImproperlyConfigured – Raises an
ImproperlyConfiguredexception on falsy values, with an error message.