Dynaconf base files
I use Dynaconf
frequently to manage loading my project's settings from a local file (config/settings.local.toml
) during development, and environment variables when running in a container. Dynaconf
allows for overriding configurations by setting environment variables.
To load configurations from the environment, you can:
- Set environment variables by prepending them with the configured
envvar_prefix
value of aDynaconf()
instance- Example: To set a value
LOG_LEVEL
:export DYNACONF_LOG_LEVEL=...
- Example: To set a value
- Create a
config/settings.local.toml
file- The
config/settings.toml
file should not be edited, nor should it contain any real values - This file is meant to be added to source control, then copied to
config/settings.local.toml
during local development - Set your real values in
config/settings.local.toml
- The
settings.toml base
Note
The Database
section is commented below because not all projects will start with a database. This file can still be copy/pasted to config/settings.toml
/config/settings.local.toml
as a base/starting point.
.secrets.toml base
config/.secrets.toml | |
---|---|
My Pydantic config.py file
Warning
This code is highly specific to the way I structure my apps. Make sure to understand what it's doing so you can customize it to your environment, if you're using this code as a basis for your own config.py
file
Note
Notes:
The following imports/vars/classes start out commented, in case the project is not using them or they require additional setup:
- All SQLAlchemy imports
- The
valid_db_types
list (used to validateDBSettings.type
) - The
DYNACONF_DB_SETTINGS
Dynaconf settings object - The
DBSettings
class definition
If the project is using a database and SQLAlchemy as the ORM, uncomment these values and modify your config/settings.local.toml
& config/.secrets.toml
accordingly.