Configuration Management for Python β
MIT License
Bot releases are hidden (Show)
Published by rochacbruno about 4 years ago
Published by rochacbruno about 4 years ago
Published by rochacbruno about 4 years ago
Published by rochacbruno about 4 years ago
Published by rochacbruno about 4 years ago
Published by rochacbruno about 4 years ago
Published by rochacbruno about 4 years ago
Published by rochacbruno over 4 years ago
Published by rochacbruno over 4 years ago
Published by rochacbruno over 4 years ago
Published by rochacbruno over 4 years ago
Published by rochacbruno almost 5 years ago
Published by rochacbruno almost 5 years ago
Published by rochacbruno about 5 years ago
Published by rochacbruno about 5 years ago
Published by rochacbruno about 5 years ago
Lets say you have a configuration like this:
settings.py
DATABASES = {
'default': {
'NAME': 'db',
'ENGINE': 'module.foo.engine',
'ARGS': {'timeout': 30}
}
}
And now you want to change the values of ENGINE
to other.module
, via environment variables you can use the format ${ENVVAR_PREFIX}_${VARIABLE}__${NESTED_ITEM}__${NESTED_ITEM}
Each __
(dunder, a.k.a double underline) denotes access to nested elements in a dictionary.
So
DATABASES['default']['ENGINE'] = 'other.module'
Can be expressed as environment variables as:
export DYNACONF_DATABASES__default__ENGINE=other.module
NOTE: if you are using Django extension then the prefix will be
DJANGO_
instead ofDYNACONF_
and the same if you are usingFLASK_
or a custom prefix if you have customized theENVVAR_PREFIX
.
This will result in
DATABASES = {
'default': {
'NAME': 'db',
'ENGINE': 'other.module',
'ARGS': {'timeout': 30}
}
}
.from_env
easy access to different envsReturn a new isolated settings object pointing to specified env.
Example of settings.toml::
[development]
message = 'This is in dev'
foo = 1
[other]
message = 'this is in other env'
bar = 2
Then you can use from_env
:
>>> print(settings.from_env('other').MESSAGE)
'This is in other env'
>>> print(settings.from_env('other').BAR)
2
>>> print(settings.from_env('other').FOO)
AttributeError: settings object has no attribute 'FOO'
The existing settings
object remains the same.
>>> print(settings.MESSAGE)
'This is in dev'
Read more on: https://dynaconf.readthedocs.io/en/latest/guides/advanced_usage.html#from-env
$dynaconf list -o
export your settings as a filedynaconf list -o path/to/file.yaml
The above command will export all the items showed by dynaconf list
to the desired format which is inferred by the -o
file extension, supported formats yaml, toml, ini, json, py
When using py
you may want a flat output (without being nested inside the env key)
dynaconf list -o path/to/file.py --output-flat
Read more on: https://dynaconf.readthedocs.io/en/latest/guides/cli.html#exporting-current-environment-as-a-file
If you want to write to specific env
pass the -e
option.
$ dynaconf write redis -v name=Bruno -v database=localhost -v port=1234 -e production
The above data will be recorded in redis as a hash:
DYNACONF_PRODUCTION {
NAME='Bruno'
DATABASE='localhost'
PORT='@int 1234'
}
Then to access that values you can set export ENV_FOR_DYNACONF=production
or directly via settings.from_env('production').NAME
Read more on: https://dynaconf.readthedocs.io/en/latest/guides/external_storages.html
Dynaconf 2.1.0
Bruno Rocha (8):
Release version 2.0.4
Merge branch 'dgarcia360-master'
Fix #197 add support for DOTTED__ENV__VARS (#215)
Add support to export merged env to filesystem via cli. (#217)
Adds `from_env` method and change `_store` to be a `DynaBox` (#219)
hotfix: next release will be 2.1.0 because new features added. (#220)
Fix `make test_examples` to use better assertions, redis and vault loader now respects `envs` (#222)
fix #221 removed JSON,YAML,INI,TOML cosntants from default_settings (#223)
Kedar Kulkarni (1):
Add `list_envs` function to vault loader and now envs can have `_` on its name.
Pavel Alimpiev (1):
Fix typo in documentation for a Validator class (#213)
dgarcia360 (3):
Updated configuration options table to csv table
Added responsive table fix
Fix format
Published by rochacbruno about 5 years ago
Published by rochacbruno over 5 years ago
Published by rochacbruno over 5 years ago
Published by rochacbruno over 5 years ago