A simple recursive loader.
Loader syntax: @<loader_name>[-loader_name...]:<loader_variable>
pip install git+https://github.com/Dog-Egg/configat.gitconfig.py
import configat
DB_PASSWORD = configat.resolve("@env:DB_PASSWORD")
print(DB_PASSWORD)$ export DB_PASSWORD=my_password
$ python config.py
my_passwordNo need to change the code. To load the password from a file, simply change the DB_PASSWORD environment.
$ echo "my_secret_password" > $(pwd)/db_password
$ export DB_PASSWORD=@file-strip:$(pwd)/db_password # A series loader is used here
$ python config.py
my_secret_passwordenv- Load from a environment variable.file- Load from a file.strip- It is usually used together with other loaders, strip the whitespace characters on both sides of the content.json- Load from a JSON string.
import configat
PORT = configat.resolve("@env:PORT", cast=int)configat provides a document generator to extract the config expressions from the code. It is useful to generate documentation for the config.
pip install "configat[docgen] @ git+https://github.com/Dog-Egg/configat.git"python -m configat.docgen .Output Example:
| Config | Required | Help |
|---|---|---|
| @env:VAR1 | Yes | help text |
| @env:VAR2 | No | |
| @file:/run/file | Yes |