Dynamic configuration management for Django with admin UI, type casting, and optional encryption.
Project description
django-dynconfig
Dynamic configuration management for Django. Store settings in the database, manage them through the admin, and access them with a simple API. Supports type casting, optional encryption for secrets, and caching.
Features
- Simple API —
get_config("key")from anywhere in your code - Typed values — Automatic casting to
str,int,float,bool,list, orjson - Admin UI — Manage configs in Django admin with grouping, search, and filtering
- Optional encryption — Encrypt sensitive values (API keys, secrets) at rest
- Caching — Uses Django's cache framework with automatic invalidation on save/delete
- Import/Export — Management commands to move configs between environments
Quick Start
pip install django-dynconfig
Add to your INSTALLED_APPS and run migrations:
# settings.py
INSTALLED_APPS = [
...
"dynconfig",
]
python manage.py migrate
That's it. Open the Django admin and start adding configurations, or use the API:
from dynconfig import get_config, set_config
# Set a config (creates it if it doesn't exist)
set_config("notifications.enabled", True)
set_config("billing.max_retries", 5)
set_config("billing.api_key", "sk_live_...", is_encrypted=True, group="billing")
# Get a config (typed automatically)
get_config("notifications.enabled") # → True (bool)
get_config("billing.max_retries") # → 5 (int)
get_config("billing.api_key") # → "sk_live_..." (decrypted)
get_config("missing.key", default=10) # → 10
Usage
Type Casting
Values are stored as strings in the database and cast to Python types on retrieval based on the value_type field:
| value_type | Python type | Example stored | Example returned |
|---|---|---|---|
string |
str |
"hello" |
"hello" |
integer |
int |
"42" |
42 |
float |
float |
"3.14" |
3.14 |
boolean |
bool |
"true" |
True |
json |
dict/list |
'{"a": 1}' |
{"a": 1} |
list |
list |
"a, b, c" |
["a", "b", "c"] |
When using set_config(), the type is auto-detected from the Python value if not specified.
Groups
Organize configs by group for cleaner admin views:
set_config("asaas.api_key", "...", group="billing")
set_config("asaas.webhook_secret", "...", group="billing")
# Get all configs in a group
from dynconfig import get_configs_by_group
billing = get_configs_by_group("billing")
# → {"asaas.api_key": "...", "asaas.webhook_secret": "..."}
Encryption
For sensitive values like API keys and secrets:
pip install django-dynconfig[encryption]
# settings.py
DYNCONFIG_ENCRYPTION_KEY = env("DYNCONFIG_ENCRYPTION_KEY")
Generate a key:
from cryptography.fernet import Fernet
print(Fernet.generate_key().decode())
Encrypted values are stored as ciphertext in the database and decrypted transparently on read. The admin shows •••••••• instead of the raw value.
Management Commands
# Export all configs to JSON
python manage.py exportconfigs -o configs.json
# Export only a specific group, excluding secrets
python manage.py exportconfigs -g billing --no-secrets -o billing.json
# Import configs (skip existing by default)
python manage.py importconfigs configs.json
# Import and overwrite existing
python manage.py importconfigs configs.json --overwrite
# Preview without changes
python manage.py importconfigs configs.json --dry-run
Settings
All settings are optional with sensible defaults:
| Setting | Default | Description |
|---|---|---|
DYNCONFIG_CACHE_BACKEND |
"default" |
Django cache backend to use |
DYNCONFIG_CACHE_TIMEOUT |
300 |
Cache TTL in seconds |
DYNCONFIG_CACHE_PREFIX |
"dynconfig" |
Cache key prefix |
DYNCONFIG_ENCRYPTION_KEY |
None |
Fernet key for encryption |
DYNCONFIG_RAISE_NOT_FOUND |
False |
Raise ConfigNotFoundError instead of returning None |
Django System Checks
Run python manage.py check to verify your configuration. dynconfig will warn you if encrypted config entries exist but DYNCONFIG_ENCRYPTION_KEY is not set.
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_dynconfig-0.1.0.tar.gz.
File metadata
- Download URL: django_dynconfig-0.1.0.tar.gz
- Upload date:
- Size: 16.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9cc4c3cf7ba9930fc88cefdef6a8d4a543acbb5da503bcdd4b44747c3faeb848
|
|
| MD5 |
24453f442823343b47e2a519e1d1c4f6
|
|
| BLAKE2b-256 |
6bdef25886c8d6fb6439c5fc153cdd35fc7547e431ec5fbb9190c9fd4f7eccc2
|
Provenance
The following attestation bundles were made for django_dynconfig-0.1.0.tar.gz:
Publisher:
publish.yml on msantino/django-dynconfig
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_dynconfig-0.1.0.tar.gz -
Subject digest:
9cc4c3cf7ba9930fc88cefdef6a8d4a543acbb5da503bcdd4b44747c3faeb848 - Sigstore transparency entry: 1018287388
- Sigstore integration time:
-
Permalink:
msantino/django-dynconfig@187686d4dd94816023d53393bc19151d32348a77 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/msantino
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@187686d4dd94816023d53393bc19151d32348a77 -
Trigger Event:
release
-
Statement type:
File details
Details for the file django_dynconfig-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_dynconfig-0.1.0-py3-none-any.whl
- Upload date:
- Size: 17.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8dc757914c8d53cc3425e113d50e4e756889f65a489e65839282c9aa477e16c0
|
|
| MD5 |
05ea528d24e9987c132185a590f698fe
|
|
| BLAKE2b-256 |
8e86cbed5d41554622407d93ed9e7ad9daa5b9a204926fabf00d341b9ce84ca0
|
Provenance
The following attestation bundles were made for django_dynconfig-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on msantino/django-dynconfig
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_dynconfig-0.1.0-py3-none-any.whl -
Subject digest:
8dc757914c8d53cc3425e113d50e4e756889f65a489e65839282c9aa477e16c0 - Sigstore transparency entry: 1018287394
- Sigstore integration time:
-
Permalink:
msantino/django-dynconfig@187686d4dd94816023d53393bc19151d32348a77 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/msantino
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@187686d4dd94816023d53393bc19151d32348a77 -
Trigger Event:
release
-
Statement type: