In Dynaconf 3.0.0 we introduced some improvements and with those improvements it comes some breaking changes.
Some of the changes were discussed on the 1st Dynaconf community meeting video is available and meeting notes #354.
- Validators now implements
|and&operators to allowValidator() &| Validator()and has moreoperationsavailable such aslen_eq, len_min, len_max, startswith#353. - First level variables are now allowed to be
lowercaseit is now possible to accesssettings.fooorsettings.FOO#357. - All Dependencies are now vendored, so when installing Dynaconf is not needed to install any dependency.
- Dynaconf configuration options are now aliased so when creating an instance of
LazySettings|FlaskDynaconf|DjangoDynaconfit is now possible to pass instead ofENVVAR_PREFIX_FOR_DYNACONFjustenvvar_prefixand this lowercase alias is now accepted. - Fixed bugs in
mergeand deprecated the@resettoken. - Added implementation for
__dir__to allow auto complete for terminal and IDEs. - Add option to override mount point for vault server.
LazySettingsis now aliased toDynaconfDynaconfclass now accepts a parametervalidators=[Validator, ...]that will be immediately evaluated when passed.
NOTE 1
from dynaconf import settingswill keep working until version4.0.xto allow users to migrate gradually without having breaking changes but it will raise some DeprecationWarnings.
NOTE 2 If you are using
FLASKorDJANGOplugins there will be no breaking change on the framework settings, a.k.a your project will keep working fine!.
Users are now supposed to create their own instance of settings instead of using the deprecated from dynaconf import settings.
project/config.py
from dynaconf import Dynaconf
settings = Dynaconf(**options)and then in your program you do from project.config import settings instead of from dynaconf import settings.
The **options are any of the dynaconf config options
ex:
settings = Dynaconf(
settings_file=["settings.toml", ".secrets.toml"],
envvar_prefix="MYPROJECT"
)With the above instance your
settingswill load data from those 2.tomlfiles and also environment variables prefixed withMYPROOJECTe.g:export MYPROJECT_FOO=1
Historically Dynaconf worked in a multi layered environments for loading data from files, so you were supposed to have a file like:
[default]
key = 'value'
[production]
key = 'value'Now starting on 3.0.0 the environments are disabled by default, so the same file can be crated as.
key = 'value'And you can still have the environments but only if you explicit specify it when creating your instance.
To have the previous behavior supporting all environments from the first level of a file.
settings = Dynaconf(
environments=True
)or to strictly specify your environments.
settings = Dynaconf(
environments=["default", "prodution", "testing", "xyz"],
)Once it is defined all the other functionalities still works such as.
export ENV_FOR_DYNACONF=production myprogram.pyStarting on 3.x Dynaconf will now only load files passed explicitly to settings_file option when creating the instance or specified as env var SETTINGS_FILE_FOR_DYNACONF.
When creating the settings instance the file paths or globs should be specified unless you want only env vars and external loaders to be loaded.
Single file
settings = Dynaconf(
settings_file="settings.toml",
)Or multiple files.
settings = Dynaconf(
settings_file=["settings.toml", "path/*.yaml"],
)Dynaconf will respect the exact order informed by you on the settings_file parameter.
NOTE the parameters
preload,includesandsecretcontinues to work in the same way as before. NOTE the parameterspreload,includesandsecretcontinues to work in the same way as before.
Dynaconf will NO MORE automatically load the data from .env file and will do that only
if load_dotenv=True is provided.
settings = Dynaconf(
load_dotenv=True
)BY default it keeps searching for files in the current PROJECT_ROOT named .env and the dotenv_path accepts a relative path such as .env or path/to/.env
There is no more logging or debug messages being printed, so the variable DEBUG_LEVEL has no more effect.
- Support for Pydantic BaseSettings for Validators.
- Support for replacement of
tomlparser on envvars loader.