Dynaconf is Configuration Management for Python.
- Inspired by the 12-factor application guide
- Settings management (default values, validation, parsing, templating)
- Protection of sensitive information (passwords/tokens)
- Multiple file formats
toml|yaml|json|ini|py
and also customizable loaders. - Full support for environment variables to override existing settings (dotenv support included).
- Optional layered system for multi environments
[default, development, testing, production]
(also called multi profiles) - Built-in support for Hashicorp Vault and Redis as settings and secrets storage.
- Built-in extensions for Django and Flask web frameworks.
- CLI for common operations such as
init, list, write, validate, export, get
. - and many more features...
Install from pypi
pip install dynaconf
Read the docs on Dynaconf.com
config.py
from dynaconf import Dynaconf
settings = Dynaconf(
envvar_prefix="APP",
settings_files=["default_settings.toml"],
environments=["production", "development"]
)
default_settings.toml
(yaml, ini, json, py, cfg, etc...)
[default]
name = "Default Name"
debug = true
data = {value=1}
[development]
name = "amber"
[production]
debug = false
name = "@vault /take/from/vault/secret"
main.py
from config import settings
if settings.debug:
print(f"Hello {settings.name}")
print(settings.data.value)
print(settings.get("key", default="a default value for you"))
print(settings["NAME"], ", this also works as a dict")
console
$ python main.py
Hello amber
1
a default value for you
amber, this also works as a dict
# Environment Variables overrides
$ APP_NAME=Bruno python main.py
Hello Bruno
# Nested env vars works
$ APP_NAME=admin APP_DATA__VALUE=42 python main.py
Hello admin
42
Read the docs on Dynaconf.com