Accessing parameters

Dynaconf offers different ways to access settings parameters

Assuming the following settings.toml file

host = "server"
port = 5555
auth = {user="admin", passwd="1234"}

As attributes (dot notation)

Using dot notation

Raises: AttributeError if not defined

As dictionary [item]

Using item access

Raises: KeyError if not defined

Default values (get)

Using dict style get

settings.get('TIMEOUT', 300)
Returns the default (300) if not defined

Using dotted-path lookup

settings.get('AUTH.USER', 'anonymous')
Returns the default (‘anonymous’) if not defined

Explicitly disabling dotted-path lookup

settings.get('AUTH.USER', dotted_lookup=False)

Forcing type casting


Available casts:

  • as_int
  • as_float
  • as_bool
  • as_json

Boxed values

In Dynaconf values are Boxed, it means the dot notation can also be used to access dictionary members, example:


mysql = {host="", port=3600, auth={user="admin", passwd=1234}}

You can now access

from dynaconf import settings


Export settings as a Python dictionary

After exporting the settings to a python dictionary it is easy to use it to serialize as a JSON, YAML or any other format you may need.


from dynaconf import settings
settings.as_dict()  # a dict with only user defined values in current env
settings.as_dict(env='production')  # a dict with only user defined values in production env
settings.as_dict(internal=True)  # a dict with all values, user defined and dynaconf internal

CLI (export to json)

from your project root folder (generally the same place where you have .env or from where you call your scripts.

dynaconf list -o path/to/file.json
dynaconf list -e production -o path/to/file.json