django-constance

A Django app for storing dynamic, admin-editable settings in pluggable Redis or database backends.

Library
PyPI
v4.3.5
1,852stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
66/100Good
Development Activity60
Maintenance40
Community76
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
81/100Excellent
Architecture84
Code Quality86
Innovation72
Learning Curve80

django-constance lets you define settings that can be changed at runtime through the Django admin, instead of being frozen in your settings.py and requiring a redeploy to update. You declare each dynamic setting with a default and help text, and Constance surfaces them in a dedicated admin page where staff can edit values live.

Values are persisted in pluggable backends — a built-in Redis backend and a Django model (database) backend ship out of the box — with optional caching to avoid per-request lookups. It supports typed fields, custom field configuration, fieldsets for organizing the admin UI, and integrates with Django’s checks framework, making it a mature choice for feature flags and operational toggles.

What You Get

  • Runtime-editable settings surfaced in a dedicated Django admin page
  • Pluggable backends: a Redis backend and a Django database/model backend
  • A simple config accessor for reading dynamic values in code
  • Typed fields with custom widgets, help text, and admin fieldsets
  • Optional caching to avoid a backend hit on every access
  • Integration with Django’s system checks framework

Common Use Cases

  • Feature flags that staff can toggle without deploying
  • Operational settings like rate limits or banner text edited by non-developers
  • A/B or maintenance switches changed live from the admin

Under The Hood

Architecture - Settings are declared in CONSTANCE_CONFIG and accessed through a lazy config proxy (constance/base.py) that delegates reads/writes to a configured backend implementing a common interface (constance/backends/: database.py, redisd.py, memory.py). The database backend stores values in a single model (constance/models.py) and can layer Django’s cache on top; admin integration (constance/admin.py, forms.py) generates a form dynamically from the declared field types. Signals notify on changes and a checks module validates configuration at startup.

Tech Stack - Pure Python packaged via pyproject.toml, targeting Django as the host framework; the Redis backend depends on redis, while the database backend uses Django’s ORM and cache framework. Codecs (constance/codecs.py) handle serialization of typed values into the backing store.

Code Quality - The tests/ suite is broad and mature, covering admin, CLI, async access, system checks, and each backend against mock Redis/cache layers, run across a Django/Python matrix via tox.ini. As a long-lived Jazzband project with 160+ contributors it follows disciplined review and release practices.

API Design - Day-to-day use is a single import — from constance import config then config.MY_SETTING — which mirrors Django’s own settings access and keeps the learning curve low. Configuration is declarative via dictionaries in settings.py, with fieldsets and custom fields available when needed, so simple setups stay terse while advanced typing and backends remain within reach.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search