Accessing parameters

Dynaconf offers different ways to access settings parameters

Assuming the following file

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

As attributes (dot notation)

Using dot notation

settings.HOST

Raises: AttributeError if not defined

As dictionary [item]

Using item access

settings['PORT']

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

settings.as_int('PORT')

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:

settings.toml

[default]
mysql = {host="server.com", port=3600, auth={user="admin", passwd=1234}}

You can now access

from dynaconf import settings

connect(
    host=settings.MYSQL.host,
    port=settings.MYSQL.port,
    username=settings.MYSQL.auth.user,
    passwd=settings.MYSQL.auth.get('passwd'),
)