Skip to content
RDDLabPublic

About

Django extension for creating and managing global application configuration

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

Django-GC

License: MIT Version: 1.1.6 Ruff pyrefly PyPI Python 3.12, 3.13, 3.14 and 3.15 PyPI djversions PyPI status PyPI - Downloads PyPI - Types


Tests pre-commit.ci status


Documentation: https://django-gc.rdd-lab.com/

Source Code: https://github.com/RDDLab/Django-GlobalConfig


Django-GC

Django-GC stores typed runtime settings in the database and uses a shared cache when configured. Application code never reads a value through the ORM. The project owns the keys; this package is the mechanism.

Features

  • Code-declared keys — categories and definitions live in Django settings and are synchronized by initialize_global_configs.
  • Typed values — strings, numbers, dates, arrays, choices, JSON, UUID, and optional secure secrets.
  • Targeted cache updates — saving one setting refreshes only its typed cache entry.
  • Full recovery snapshot — a miss in a shared cache rebuilds the snapshot.
  • Direct database reads — local-memory and dummy caches use current values from the database.
  • Stock Django Admin — edit values with standard ModelAdmin and Django's built-in change history.
  • Optional Celery — periodic full snapshot refresh.
  • Fully typed — ships py.typed; compatible with pyrefly and standard type checkers.

Requirements

Python Minimum Django
3.12, 3.13, 3.14 6.0
3.15 6.1.3

Installation

pip install 'django-gc>=1.1.6'
INSTALLED_APPS = [
    'django_gc',
    'django.contrib.admin',
    # ...
]

Periodic refresh is optional:

pip install 'django-gc[celery]'

Quick start

Declare categories and keys in Django settings. Set the encryption key through your deployment configuration before using SECURE values.

from enum import StrEnum

from django_gc import (
    CategoryDefinition,
    SettingDefinition,
    SettingType,
)


class SettingKey(StrEnum):
    MAINTENANCE_ENABLED = 'platform.maintenance_enabled'


GLOBAL_CONFIG_CATEGORIES = [
    CategoryDefinition(id=1, code='platform', name='Platform'),
]
GLOBAL_CONFIG_DEFINITIONS = [
    SettingDefinition(
        key=SettingKey.MAINTENANCE_ENABLED,
        description='Maintenance mode',
        default_value=False,
        value_type=SettingType.BOOLEAN,
        category_id=1,
    ),
]
python manage.py migrate
python manage.py initialize_global_configs

After Django has initialized, use the runtime API from application code.

from django_gc import get_value, set_typed_value

enabled = get_value("platform.maintenance_enabled")
set_typed_value(key="platform.maintenance_enabled", value=True)

Documentation

Getting started · Upgrade and operations · Documentation deployment

После создания схемы и при обновлении definitions выполните uv run python manage.py initialize_global_configs. Миграции не создают категории и значения GC. Существующие значения сохраняются.

The metadata template uses the standard Django template loader. Project templates may override its logical name.

About

Django extension for creating and managing global application configuration

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages