You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ cd path/to/your/project/
$ dynaconf init -f toml
βοΈ Configuring your Dynaconf environment
------------------------------------------
π The file `config.py` was generated.
ποΈ settings.toml created to hold your settings.
π .secrets.toml created to hold your secrets.
π the .secrets.* is also included in `.gitignore`
beware to not push your secrets to a public repo.
π Dynaconf is configured! read more on https://dynaconf.com
TIP: You can select toml|yaml|json|ini|py on dynaconf init -f <fileformat>toml is the default and also the most recommended format for configuration.
Dynaconf init creates the following files
.
βββ config.py # This is from where you import your settings object (required)
βββ .secrets.toml # This is to hold sensitive data like passwords and tokens (optional)
βββ settings.toml # This is to hold your application settings (optional)
On the file config.py Dynaconf init generates the following boilerpate
fromdynaconfimportDynaconfsettings=Dynaconf(
envvar_prefix="DYNACONF", # export envvars with `export DYNACONF_FOO=bar`.settings_files=['settings.yaml', '.secrets.yaml'], # Load files in the given order.
)
TIP: You can create the files yourself instead of using the init command as shown above and you can give any name you want instead of the default config.py (the file must be in your importable python path) - See more options that you can pass to Dynaconf class initializer on https://dynaconf.com
Using Dynaconf
Put your settings on settings.{toml|yaml|ini|json|py}
Put sensitive information on .secrets.{toml|yaml|ini|json|py}
password = "secret123"
IMPORTANT:dynaconf init command puts the .secrets.* in your .gitignore to avoid it to be exposed on public repos but it is your responsibility to keep it safe in your local environment, also the recommendation for production environments is to use the built-in support for Hashicorp Vault service for password and tokens.
Optionally you can now use environment variables to override values per execution or per environment.
# override `port` from settings.toml file and automatically casts as `int` value.export DYNACONF_PORT=9900
On your code import the settings object
frompath.to.project.configimportsettings# Reading the settingssettings.username=="admin"# dot notation with multi nesting supportsettings.PORT==9900# case insensitivesettings['password'] =="secret123"# dict like accesssettings.get("nonexisting", "default value") # Default values just like a dictsettings.databases.name=="mydb"# Nested key traversingsettings['databases.schema'] =="main"# Nested key traversing