dynaconf v2.1.0 Release Notes

Release Date: 2019-09-05 // over 4 years ago
  • Highlights:

    🍱 🐲Nested envvars w/ DUNDER__KEYS (useful for #django)

    πŸ”§ 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 of DYNACONF_ and the same if you are using FLASK_ or a custom prefix if you have customized the ENVVAR_PREFIX.

    This will result in

    DATABASES = { 'default': { 'NAME': 'db', 'ENGINE': 'other.module', 'ARGS': {'timeout': 30} } }
    

    βœ… Read more on: https://dynaconf.readthedocs.io/en/latest/guides/environment_variables.html#nested-keys-in-dictionaries-via-environment-variables

    🍱 πŸ”ƒ.from_env easy access to different envs

    Return 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 file

    dynaconf 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

    πŸ”’ πŸ”@hashicorp #Vault & @RedisLabs supports multiple envs

    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