Skip to main content

Django settings dict

This is small helper that makes it easier to store distributable django app settings in project settings.py 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.

Example

Setting defitions in your applications app_settings.py (for example):

from django_settingsdict import SettingsDict
REQUIRED = (
    'IMPORTANT_SETTING',
)
DEFAULTS = {
    'URL_NAME': 'test_app',
    'MIGRATED_VALUE': 'something old, but supported',
    'REVERSE_FUNC': 'django.core.urlresolvers.reverse',
}
IMPORT_STRINGS = (
    'REVERSE_FUNC',
)
REMOVED = (
    'OLD_SETTING',
)
MIGRATE = (
    ('MIGRATED_VALUE', 'MY_APP_OLD_OPTION'),
)
app_settings = SettingsDict('MY_APP',
                            required=REQUIRED,
                            defaults=DEFAULTS,
                            removed=REMOVED,
                            migrate=MIGRATE,
                            import_strings=IMPORT_STRINGS)

Configuration in your projects settings.py:

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

print(app_settings.IMPORTANT_SETTING)
print(app_settings.URL_NAME)
print(app_settings.REVERSE_FUNC)
print(app_settings.MIGRATED_VALUE)

would make following result:

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

Metadata

Release files for django-settingsdict 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-settingsdict 1.1.1
File Size Uploaded Provenance Actions
django-settingsdict-1.1.1.tar.gz 5.2 kB Without provenance Details for django-settingsdict-1.1.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for django-settingsdict 1.1.1
File Interpreter ABI Platform Actions
django_settingsdict-1.1.1-py3.7.egg Legacy Egg format - - Details for django_settingsdict-1.1.1-py3.7.egg
django_settingsdict-1.1.1-py3-none-any.whl Python 3 none any Details for django_settingsdict-1.1.1-py3-none-any.whl

Total release size: 16.5 kB

Release files / django-settingsdict-1.1.1.tar.gz

Download URL django-settingsdict-1.1.1.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6d06f565dfe3645d4a15f6104f3c4be36085bd600f8e15473bcb5e0c66ed229d
BLAKE2b-256 checksum
How to use checksums
d57f42c599138cfeace16a81ffa3bb6cbe19a3464cacf28fc8abeb74dd9f0749
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.7

Release files / django_settingsdict-1.1.1-py3.7.egg

Download URL django_settingsdict-1.1.1-py3.7.egg
Size 6.4 kB
Tags Egg
SHA-256 checksum
How to use checksums
83c21018d71a64a6906e173548178dc2c523c611a451fd3af4df8fdf7ce5e33d
BLAKE2b-256 checksum
How to use checksums
7f57e06eb47c7bf97d30be928c14dea892a479f390afb079cc27c16cf47de8a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.7

Release files / django_settingsdict-1.1.1-py3-none-any.whl

Download URL django_settingsdict-1.1.1-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4fd2ab750a239b2a16ef086bca1937ad677b3137e97eaeec61a36b39368bb173
BLAKE2b-256 checksum
How to use checksums
1e30d89ec036aab6951f61e4bcff34c6cb4622865b2eab0f802d6e7cad396c7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.7

Security for django-settingsdict 1.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page