Dynaconf: Dynamic settings configuration for Python apps
Dynaconf is a dynamic configuration for Python applications. With it, you can set one canonical settings module to use for all instances. Users can also change their dynamic parameters without having to deploy their application. This settings config tool for Python offers extensions for both Flask and Django.
As Python’s popularity continues to grow, so too does its ecosystem of available open source tools. Many tools intend to streamline workflow and save developers time when creating apps.
Today we focus on one such tool: Dynaconf.
Dynaconf, the dynamic configuration system for Python apps, helps manage settings in newly created Python projects. It supports 12-factor applications and extensions.
It’s also a good secret keeper. The additional secrets file stores sensitive information, such as
TOKEN, in the
.secrets file or
vault server. With this feature, security sensitive data will not be sent to a public git repo by mistake.
Built-in support for the Vault Project from Hashicorp adds another layer of security for secrets protection. You can also have an extra
secrets file available only when specific CI environments are running.
From the documentation, some more of its noteworthy features:
- Follows the 12-factor application guide and separates settings from code.
- Define comprehensive default values
- Support for storing parameters in .toml, .json, .yaml (with
PyYAMLinstalled), .ini and .py formats.
- Feature flag system
- Optional parameter storage in external services
- Layered [environment] system.
- Override parameters with environmental variables.
- Support for
.envfiles to automate the export of environment variables.
- Correct data types
- One canonical settings module can be used for all future instances
- Manage settings via your console with $ dynaconf CLI
- Validation of settings parameters
- Change dynamic parameters without having to redeploy your application
- Create your own custom loader
- Tested on Windows and Linux
Hands-off settings management
Project contributor and Red Hat software engineer Bruno Rocha wrote an introduction to Dynaconf. This introduction explores its use cases and starting instructions. According to Bruno Rocha’s tutorial, Dynaconf only requires one line of code to set up:
He writes: “there is no magic, and the values can come from wherever you want, by default and following the recommendations of the 12 factor apps Dynaconf has preference for environment variables.”
Default installation supports .toml, .py, and .json file formats, as well as .env environmental variables.
Have you used it in your apps? Give Dynaconf feedback on how to improve new versions here.