add via pip:
pip install https://github.com/anfema/configloader/releases/1.0/download/configloader-1.0.0-py3-none-any.whl
from configloader import Configuration
config = Configuration(base_name="backend")
# Access keys with path-like strings like so:
xyz = config['toplevel.sublevel.xyz']YAML config files are searched in this order:
$HOME/etc/backend.yaml$HOME/etc/backend.yml./backend.yaml./backend.yml
if you initialized with another base_name, replace backend with that.
YAML config file example:
toplevel:
sublevel:
xyz: "bla"To override configuration from config files you can set environment variables.
By default we search for env variables beginning with CONFIG_, you can override
this prefix by setting environment_prefix in a YAML config that is loaded before
overrides are processed.
All env variables are stripped of their prefix and then lowercased and delinearized (see below).
Example override:
export CONFIG_TOPLEVEL__SUBLEVEL__XYZ="bla"If none of the default config files can be found we try to load alternatives from alternative locations (mostly to be able to use K8S configmaps mouted as volumes):
- We check if we can find any files in
/code/config- If we find
ymloryamlfiles those are loaded like normal YAML files - If we find files without an extension we load the content with the name of the file as a key.
- If we find
- The same happens for
/code/secrets - All keys found this way are delinearized (see below)
Example YAML:
toplevel__sublevel__xyz: "bla"Example bare config file:
$ ls /code/config
toplevel__sublevel__xyz
$ cat /code/config/toplevel__sublevel__xyz
bla
If the keys contain double underscores we split them up into key-paths like
the django ORM would do: subkey__key will be split into subkey with a
member key.
Setting values to null will result in None at the python side.