Dynaconf is a dynamic configuration management library for Python projects, inspired by the 12-factor application guide. It supports multiple file formats (TOML, YAML, JSON, INI, Python), environment variables, Hashicorp Vault, and Redis for settings and secrets. It provides a flexible, layered system for multi-environment configurations and includes built-in extensions for Flask and Django. The library is actively maintained, with the current version being 3.2.13, and receives regular updates and bug fixes.
pip install dynaconfVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize Dynaconf, load settings from specified TOML files (including a secrets file), and access configuration values. It highlights the importance of explicitly enabling `load_dotenv` and `environments` in version 3.x and shows how to access values, including sensitive ones, with a fallback to environment variables for production readiness.
Replace `from dynaconf import settings` with `from dynaconf import Dynaconf; settings = Dynaconf(...)`. Make sure to pass your `settings_files` explicitly.
When initializing `Dynaconf`, provide a list of your configuration files: `settings = Dynaconf(settings_files=['settings.toml', '.secrets.toml'])`.
To enable `.env` file loading, set `load_dotenv=True` during `Dynaconf` instantiation: `settings = Dynaconf(..., load_dotenv=True)`.
Ensure your IDE's run/test configuration sets the working directory to the root of your project. Alternatively, explicitly specify `root_path` when initializing `Dynaconf`.
Do not install or use `dynaconf==3.2.8` or `dynaconf==3.2.9`. Upgrade to `3.2.10` or later.
Upgrade to `dynaconf==3.2.13` or a later version to patch these vulnerabilities.
pip install dynaconf
Ensure Dynaconf is initialized with the correct `settings_files` and `root_path`. If using layered environments, set `environments=True` in `Dynaconf()` and verify the `ENV_FOR_DYNACONF` environment variable or `env` argument. For nested keys, use dot notation (e.g., `settings.SECTION.MY_KEY`).
Explicitly define the `root_path` in your `Dynaconf` instance using an absolute path (e.g., `Dynaconf(root_path=os.path.dirname(os.path.abspath(__file__)))`), or configure your IDE's run/debug settings to set the working directory to your project's root.
Review the setting's value to ensure it complies with the associated validator's conditions, or adjust the validator definition if its requirements are not correct for the intended configuration.