Package: configular
ConfigularSupport hierarchical loading of application settings from a number of sources.This is useful for libraries where you want to allow an including application to
provide configuration to your code from sources such as django settings,
constance, and environment values. Also supports additional custom sources.Supports optional retrieveal of secrets with values like%%example_key%%. If
no secrets managers are configured, and a value matching the format is
presented, a warning will be logged.Common hierarchy of lookups, first defined will be used:constancesettings.pyos.environSettings['key']Any value found that is surrounded by%%will be processed by the configuredsecrets_managers.Settings values are assumed to be dynamic, Settings objects use callables to
retrieve the values at run time. This means specifically that changes in the
Constance admin will apply to any look ups made after the values are saved.Secrets (at least in theCredstashManager) are assumed to be immutable. Afunctools.lru_cacheis used around the lookup for cost and performance. If
you have rotated the credentials (or need to reset the cache in tests) you can
callflush_secret_cacheon yourCredstashManagerinstance to reset thelru_cache. This means a value of%%secret%%will look up the secured value
one time and cache it in memory untilflush_secret_cacheis called.UsagefromconfigularimportSettingsfromconfigular.constance_loaderimportConstanceLoaderfromconfigular.credstash_managerimportCredstashManagerfromconfigular.django_loaderimportDjangoLoaderfromconfigular.environ_loaderimportEnvironLoaderCM=CredstashManager()loader_settings=Settings({'A_SETTING':'DEFAULT'},'TEST_PREFIX',loaders=[ConstanceLoader,DjangoLoader,EnvironLoader],secrets_managers=[CM],)To update theloadersandsecrets_managersin a settings instance, callreconfigure.fromconfigular.credstash_managerimportCredstashManagerfromconfigular.django_loaderimportDjangoLoaderfromconfigular.environ_loaderimportEnvironLoaderfrommyapp.confimportmyapp_settingsmyapp_settings.reconfigure(loaders=[DjangoLoader,EnvironLoader],secrets_managers=[CM],)ConfigurationDjango settings must be defined in a dict named with the defined prefixTEST_PREFIX={'A_SETTING':'NEW_VALUE'}Constancesettings must be named
with the prefix leading followed by an underscore, e.g.CONSTANCE_CONFIG={'TEST_PREFIX_A_SETTING':(True,'A fine setting'),}A sublcass ofdjango.core.exceptions.ImproperlyConfiguredis provided that can be
used to enforce configuration during app startup.fromconfigular.exceptionsimportImproperlyConfiguredifloader_settings.MY_APP_VERSIONnotin('2.25','2.27'):raiseImproperlyConfigured(f'MY_APP_VERSION={MY_APP_VERSION}not supported')or with a decorator for checking validationfromconfigular.decoratorsimportvalidate_setting@validate_setting(settings=loader_settings,key='MY_APP_VERSION',validate_func=lambdamy_app_version:my_app_versionin('2.25','2.27'),)deffunc()...Constance settings take precedence over defined django settings. Trying to access
a setting that is not defined in your Settings object will raiseAttributeError.Running tests locallyEnsuretoxis installed. e.g.pip install -g toxdocker-compose up -d --build  # Tests require a running react server
tox