Examples¶
Supported file formats¶
TOML¶
[default]
DEBUG = true
SERVER = "flaskdynaconf.com"
PORT = 6666
MESSAGE = "Dynaconf works like a charm with Flask and TOML"
TEST_RULE = '/flask_with_toml'
[development]
DEBUG = true
SERVER = "dev.flaskdynaconf.com"
[production]
DEBUG = false
SERVER = "prod.flaskdynaconf.com"
YAML¶
default:
DEBUG: true
SERVER: flaskdynaconf.com
PORT: 6666
MESSAGE: Dynaconf works like a charm with Flask and YAML
TEST_RULE: /flask_with_yaml
development:
DEBUG: true
SERVER: dev.flaskdynaconf.com
production:
DEBUG: false
SERVER: prod.flaskdynaconf.com
INI¶
[default]
DEBUG = true
SERVER = "flaskdynaconf.com"
PORT = 6666
MESSAGE = "Dynaconf works like a charm with Flask and INI"
TEST_RULE = '/flask_with_ini'
[development]
DEBUG = true
SERVER = "dev.flaskdynaconf.com"
[production]
DEBUG = false
SERVER = "prod.flaskdynaconf.com"
JSON¶
{
"default": {
"DEBUG": true,
"SERVER": "flaskdynaconf.com",
"PORT": 6666,
"MESSAGE": "Dynaconf works like a charm with Flask and JSON",
"TEST_RULE": "/flask_with_json"
},
"development": {
"DEBUG": true,
"SERVER": "dev.flaskdynaconf.com"
},
"production": {
"DEBUG": false,
"SERVER": "prod.flaskdynaconf.com"
}
}
PY¶
In python fils the environment
is set by prefixing the file names
settings.py
DEBUG = True
SERVER = "flaskdynaconf.com"
PORT = 6666
MESSAGE = "Dynaconf works like a charm with Flask and .py"
TEST_RULE = '/flask_with_ini'
development_settings.py
DEBUG = True
SERVER = "dev.flaskdynaconf.com"
production_settings.py
DEBUG = False
SERVER = "prod.flaskdynaconf.com"
.env¶
.env
allows only the global
environment (overrides everything)
DEBUG=true
SERVER="flaskdynaconf.com"
PORT=6666
MESSAGE="Dynaconf works like a charm with Flask and .env"
TEST_RULE='/flask_with_ini'
Using a default main config file plus variable settings file¶
On the .env
export SETTINGS_FILE_FOR_DYNACONF="default.toml"
The default file
[default]
variable1 = 'value1'
Now having specific settings per environment
Use cases:
- plugin based apps
- user specific settings
- dev specific settings
On the user1 environment
export INCLUDES_FOR_DYNACONF='/path/to/user1_specific_settings.toml'
On the user2 environment
export INCLUDES_FOR_DYNACONF='/path/to/user2_specific_settings.toml'
It can be a glob
export INCLUDES_FOR_DYNACONF='/path/to/config/*.toml'
And also supports having a ;
or ,
separated list of paths or globs.