Package: django-app-settings
Django AppSettingsApplication settings helper for Django apps.Why anotherapp settingsapp?
Because none of the other suited my needs!This one is simple to use, and works with unit tests overriding settings.Installationpip install django-app-settingsDocumentationOn ReadTheDocsDevelopmentTo run all the tests:tox. SeeCONTRIBUTING.Quick usage# Define your settings classimportappsettingsclassMySettings(appsettings.AppSettings):boolean_setting=appsettings.BooleanSetting(default=False)required_setting=appsettings.StringSetting(required=True)named_setting=appsettings.IntegerSetting(name='integer_setting')prefixed_setting=appsettings.ListSetting(prefix='my_app_')classMeta:setting_prefix='app_'# Related settings in settings.pyAPP_INTEGER_SETTING=-24MY_APP_PREFIXED_SETTING=[]# Instantiate your class wherever you need toappconf=MySettings()assertappconf.boolean_settingisFalse# True (default value)assertappconf.required_setting=='hello'# raises AttributeErrorassertappconf.named_setting<0# Trueassertappconf.prefixed_setting# False (empty list)# Values are cached to avoid perf issueswithoverride_settings(APP_REQUIRED_SETTING='hello',APP_INTEGER_SETTING=0):# ...but cache is cleaned on Django's setting_changed signalassertappconf.required_setting=='hello'# Trueassertappconf.named_setting<0# False# You can still access settings through the class itself (values not cached)print(MySettings.boolean_setting.get_value())# explicit callprint(MySettings.boolean_setting.value)# with property# Run type checking and required presence on all settings at onceMySettings.check()# raises Django's ImproperlyConfigured (missing required_setting)# MySettings.check() is best called in django.apps.AppConfig's ready methodYou can easily create your own Setting classes for more complex settings.importreimportappsettingsfromdjango.core.exceptionsimportValidationErrorclassRegexSetting(appsettings.Setting):defvalidate(self,value):re_type=type(re.compile(r'^$'))ifnotisinstance(value,(re_type,str)):# Raise ValidationErrorraiseValidationError('Value must be a string or a compiled regex (use re.compile)')deftransform(self,value):# ensure it always returns a compiled regexifisinstance(value,str):value=re.compile(value)returnvaluePlease check the documentation to see even more advanced usage.LicenseSoftware licensed underISClicense.ChangelogUnreleased0.7.2 (2023-09-07)Deprecate loding setting values from environment (#98 by @stinovlas)Fix optional nested dict setting (#92 by @rastytheamateur)Fix typos inusage.rst(#102 by @oto-stefan)Fix docs build (#100 by @stinovlas)0.7.1 (2020-05-28)Ignore environment variables when usingoverride_settings.Don’t announce type annotations.0.7.0 (2020-04-14)Read setting values from environment variables.AddFileSetting.Fix bug causingNestedDictSettingto be always required.Add support for python 3.8 and Django 3.0.Drop support for python 2.7 and 3.4.Drop deprecated type checkers.Add type annotations.RaiseImproperlyConfiguredfromSetting.checkfor all errors in a setting.Move repository tohttps://github.com/pawamoy/django-appsettings.Clean tests.0.6.1 (2020-03-04)Fixtransform_defaultinNestedListSetting, by @stinovlas (see PR#61).0.6.0 (2019-08-27)AddCallablePathSetting(see issue#49and PR#52).AddNestedListSetting(see issue#50and PR#53).RenameNestedSettingtoNestedDictSetting(old name is still available but deprecated).0.5.1 (2019-05-23)Fix default values for empty arguments.0.5.0 (2018-12-03)Deprecate setting checkers in favor of validators, similarly to Django form fields.0.4.0 (2018-07-25)AddNestedSettingfor easy management of nested settings.0.3.0 (2017-11-30)Going from alpha to beta status. Logic has been reworked.An instance of a subclass ofAppSettingswill now dynamically get
settings values from project settings, and cache them. This allows to use
the instance the same way in code and tests, without performance loss. See
issue#16.Cache is invalidated when Django sends asetting_changedsignal (i.e.
when usingTestCaseoroverride_settings). See issue#16.Setting main class now accepts callable as default value, and two new
parameters to keep control on its behavior:call_default, which tells
if the default value should be called (if callable) or not, andtransform_default, which tells if the default value should be transformed
as well by thetransformmethod. See issue#17.Settings type checkers now have custom parameters likemax_length,emptyorkey_type, that can be passed directly through the settings
classes as keyword arguments. Check the documentation for more information.Settings classes have been rewritten more explicitly, using class inheritance
instead of hard-to-debug generators. Composed types like float lists or
boolean sets have been removed in favor of more flexible list, set and tuple
types which now accept an optionalitem_typeparameter.ImportedObjectSettinghas been renamedObjectSetting, and now
supports object paths down to arbitrary level of nesting. Before, it only
supported object paths down to classes or functions, now you can for example
give it the path to a constant in a class within a class, itself contained
in a module within a package. It will work as long a the deepest module is
importable throughimportlib.import_moduleand each object down to the
last is obtainable throughgetattrmethod.Many thanks toziimafor having shared good ideas and thoughts!0.2.5 (2017-06-02)Add six dependency (now required).RenameIntsettings toInteger, andBoolones toBoolean.Remove metaclass generated getters and checkers.0.2.4 (2017-05-02)Settings are not checked when they default to the provided default value.Settings classes received better default values corresponding to their types.0.2.3 (2017-05-02)Addfull_nameproperty toSettingclass.Addrequiredparameter toSettingclass (defaultFalse).0.2.2 (2017-04-17)Import settings classes in main module to simplify imports.0.2.1 (2017-04-17)AddPositiveIntandPositiveFloatsettings.Add support for Django 1.11.Implement basic settings classes.0.2.0 (2017-04-17)Implement basic Setting class.Pin dependencies.Change distribution name toapp-settings.0.1.0 (2017-03-23)Alpha release on PyPI.