from __future__ import annotations from dynaconf import Dynaconf settings = Dynaconf(settings_files=["settings.toml"], ) assert settings.key == "value" assert settings.number == 789 assert settings.a_dict.nested.other_level == "nested value" assert settings["a_boolean"] is False assert settings.get("DONTEXIST", default=1) == 1 for item in settings: print(item) for key, value in settings.items(): # dict like iteration print(key, value)
import os, pytz, datetime, socket, pdb from dynaconf import Dynaconf DROP_SQL = 'DROP SCHEMA public CASCADE;CREATE SCHEMA public;' # load configs. Priority = config.example.yml -> config.yml -> env_vars vars = Dynaconf(settings_files=[ 'common/config.example.yml', '/storage/config.yml', 'common/config.yml' ], # environments=True ) # Dynaconf requires an env-vars prefix (like DYNACONF_DB_URL), I'll move to that later; in mean-time, # manually pulling in env vars for k, v in vars.items(): v = os.environ.get( k, v) # fall back to dynaconf val if not provided as env_var vars[k] = v # Boto3 wants env vars, can't find way to set via sdk if k and v and k.startswith("AWS_") and not os.environ.get(k, False): os.environ[k] = v # TODO switch to Dynaconf's layered environment feature https://www.dynaconf.com/configuration/#environments vars['DB_NAME'] = dict(development='gnothi_dev', production='gnothi_prod', testing='gnothi_test')[vars.ENVIRONMENT] or 'gnothi_dev' def is_prod(): return vars.ENVIRONMENT == 'production'