This release is more about bug fixes and improvements, we included a full diagram of the library to help contributors.
Dynaconf now doesn't have dependencies because the main used libraries has been vendored, in addition to the vendoring process (which followed the guidelines regarding licensing and structure) all the vendored libraries has been minified to save space on the distribution.
Ideally the vendored libraries will be upgraded on-demand only when a new security or important bug fix is released on the respective vendored repository.
Exception is python-box which the goal is to remove the dependency and implement its basic features within dynaconf/DynaBox type.
We made flake8 more strict and removed some unused imports and variables.
The mechanism to evaluate
Lazy values has been refactored and now
@jinja values can be used within dictionaries and lists in any nesting levels.
Fixed a problem when multiple combined validators are registered and fixed duplication of ValidationError messages.
All names in a must_exist clausule are now tested, before it wes stopping validation on the first failure.
- Cli now accepts dotted keys ex:
dynaconf -i config.settings list -k foo.bar.zaz
- boto is now optional for vault authentication
.formatterattrbute lookup was conflicting with Django logging so argument has been renamed.
- box_settings made optional to DynaBox
- Included an example of SOPS custom loader
settings.setis fixed so it now can set dotted attrs directly
settings.FOO = 1
- Fix a problem on object_merge to allow keys with same name
- Added username and password to Redis
- Lots of typos on docs
Providing default or computed values¶
Validators can be used to provide default or computed values.
Validator("FOO", default="A default value for foo")
Then if not able to load the values from files or environment this default value will be set for that key.
Sometimes you need some values to be computed by calling functions, just pass a callable to the
def my_function(settings, validator): return "this is computed during validation time"
If you want to be lazy evaluated
from dynaconf.utils.parse_conf import empty, Lazy Validator("FOO", default=Lazy(empty, formatter=my_function))
In Dynaconf 3.0.0 we introduced some improvements and with those improvements it comes some breaking changes.
- Validators now implements
&operators to allow
Validator() &| Validator()and has more
operationsavailable such as
len_eq, len_min, len_max, startswith#353.
- First level variables are now allowed to be
lowercaseit is now possible to access
- 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 of
envvar_prefixand this lowercase alias is now accepted.
- Fixed bugs in
mergeand deprecated the
- Added implementation for
__dir__to allow auto complete for terminal and IDEs.
- Add option to override mount point for vault server.
LazySettingsis now aliased to
Dynaconfclass now accepts a parameter
validators=[Validator, ...]that will be immediately evaluated when passed.
from dynaconf import settingswill keep working until version
4.0.xto allow users to migrate gradually without having breaking changes but it will raise some DeprecationWarnings.
NOTE 2 If you are using
DJANGOplugins there will be no breaking change on the framework settings, a.k.a your project will keep working fine!.
dynaconf.settings global settings instance is now deprecated.¶
Users are now supposed to create their own instance of
settings instead of using the deprecated
from dynaconf import settings.
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.
**options are any of the dynaconf config options
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 with
Dynaconf is now envless by default.¶
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.py
Automatic load of
settings.* files are disabled by default.¶
Starting 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.
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
NOTE the parameters
secretcontinues to work in the same way as before. NOTE the parameters
secretcontinues to work in the same way as before.
Load of dotenv
.env is now disabled by default.¶
Dynaconf will NO MORE automatically load the data from
.env file and will do that only
load_dotenv=True is provided.
settings = Dynaconf( load_dotenv=True )
BY default it keeps searching for files in the current
.env and the
dotenv_path accepts a relative path such as
DEBUG Logging is now completely removed¶
There is no more
debug messages being printed, so the variable
DEBUG_LEVEL has no more effect.
Coming in 3.1.x¶
- Support for Pydantic BaseSettings for Validators.
- Support for replacement of
tomlparser on envvars loader.