django-enhanced-settings
Allow for more complex and dynamic settings for Django.
Extras
cloud-secret-manager - Adds support for Google Cloud Secret Manager
Example
import os
from django_enhanced_settings import Settings
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
settings = Settings(BASE_DIR)
def __dir__():
return settings.dir(globals())
def __getattr__(name):
return settings.getattr(name, globals())
_DEBUG = settings.boolean_value('DJANGO_DEBUG', False)
_ALLOWED_HOSTS = settings.list_value(
'DJANGO_ALLOWED_HOSTS',
['localhost'] if _DEBUG.value else [],
split_char=';'
)
_SECRET_KEY = settings.string_value('DJANGO_SECRET_KEY', required=True)
INSTALLED_APPS = [...]
from django.conf import setings
settings.DEBUG # By default returns False
Rules
- You are not allowed to name a non
ConfigValueusing the naming scheme set for theSettingsinstance (suffix_underscore). For example, writing the following would raise aValueErrorin the above example:
_INSTALLED_APPS = [...]
- You are not allowed to name a
ConfigValuewithout using the naming scheme set for theSettingsinstance (suffix_underscore). For example, writing the following would raise aValueErrorin the above example:
SECRET_KEY = settings.string_value('DJANGO_SECRET_KEY', required=True)
- You are not allowed to define 2 variable names that result in the same accessible name. For example, writing the following would raise a
ValueErrorin the above example:
_SECRET_KEY = settings.string_value('DJANGO_SECRET_KEY', required=True)
SECRET_KEY = 'SECRET_KEY'
If you would like to customise these rules you can write your own __dir__ and __getattr__.
Cache values on first run
If you would like to cache all your static values at once, you can append Settings.cache_static_values(...) to the bottom of your settings file. For the example above, this would fetch DEBUG, ALLOWED_HOSTS and SECRET_KEY:
settings.cache_static_values()
If you are not using Settings.dir(...) and Settings.getattr(...), you may need to write your own function insead of using Settings.cache_static_values(...).
Metadata
Release files for django-enhanced-settings 0.2.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django-enhanced-settings-0.2.4.tar.gz | 5.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_enhanced_settings-0.2.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.8 kB
Release files / django-enhanced-settings-0.2.4.tar.gz
| Download URL | django-enhanced-settings-0.2.4.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
64f8172237ed0a0f50e64f626206889d80695c173f02b0202a679133bdd320ff
|
|
BLAKE2b-256 checksum How to use checksums |
19e26ff08ba5dedc989212dcb07c1ab63fef7d70c49105e92c5e76f2f3c81dcd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.5 CPython/3.8.2 Linux/5.0.0-1032-azure
|
Release files / django_enhanced_settings-0.2.4-py3-none-any.whl
| Download URL | django_enhanced_settings-0.2.4-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d94a48caa1a3850a3ef0639add12bcc4bc0371241454f8aec7416cb087ef5f8f
|
|
BLAKE2b-256 checksum How to use checksums |
34217d90f44e0c66c2f79458ebb388ad90c0bd10ac9a703785dcaa7985bd5b25
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.5 CPython/3.8.2 Linux/5.0.0-1032-azure
|