Skip to main content

Simple helper class to handle dict style settings for django app

Project description

This is small helper that makes it easier to store distributable django app settings in project as a dict. Purpose is to keep settings file simple and clean. With this it’s also easier to set defaults for the settings and warn about settings that have been removed.

Helper also supports marking settings that should be imported before returning. Import is done using django.utils.module_loading.import_string.

Helper resolves variables when requested for the first time and caches the value for faster lookup next time. Variables that are not in required or defaults raise AttributeError. If you like to clear the cache, you can use _clear_cached().

Using migrate, you can configure list of migration actions. Parameter takes a list of tuples, where first field is the new setting name, second is the old name outside of the dictionary and optional third is callable. The callable has format migrate_script(old_value: Any, current_dictionary: dict) -> Any, where current_dictionary contains all values read so far.

Design is based on class done in Django REST framework.


Setting defitions in your applications (for example):

from django_settingsdict import SettingsDict
    'URL_NAME': 'test_app',
    'MIGRATED_VALUE': 'something old, but supported',
    'REVERSE_FUNC': 'django.core.urlresolvers.reverse',
app_settings = SettingsDict('MY_APP',

Configuration in your projects

MY_APP = {
    'IMPORTANT_SETTING': 'some value',
    'URL_NAME': 'test_app_2',
MY_APP_OLD_OPTION = 'this is not fixed yet'

And in your application code:

from .app_settings import app_settings


would make following result:

some value
<function reverse at 0x7fd5119e0578>
this is not fixed yet

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-settingsdict, version 1.1.1
Filename, size File type Python version Upload date Hashes
Filename, size django_settingsdict-1.1.1-py3.7.egg (6.4 kB) File type Egg Python version 3.7 Upload date Hashes View
Filename, size django_settingsdict-1.1.1-py3-none-any.whl (5.0 kB) File type Wheel Python version 3.7 Upload date Hashes View
Filename, size django-settingsdict-1.1.1.tar.gz (5.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page