Metadata-Version: 2.4
Name: django-gc
Version: 1.1.6
Summary: Typed Django runtime configuration with database storage and shared caching
Author-email: Raman Marozau <r.morozov@rdd-lab.com>
License: MIT
Project-URL: Homepage, https://django-gc.rdd-lab.com/
Project-URL: Documentation, https://django-gc.rdd-lab.com/
Project-URL: Issues, https://github.com/RDDLab/Django-GlobalConfig/issues
Project-URL: Repository, https://github.com/RDDLab/Django-GlobalConfig
Project-URL: Changelog, https://github.com/RDDLab/Django-GlobalConfig/blob/main/CHANGELOG.md
Keywords: django,config,settings,cache,admin
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Framework :: Django
Classifier: Framework :: Django :: 6.0
Classifier: Framework :: Django :: 6.1
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: django>=6.0; python_version < "3.15"
Requires-Dist: django>=6.1.3; python_version >= "3.15"
Requires-Dist: cryptography>=44.0.0
Provides-Extra: celery
Requires-Dist: celery>=5.3; extra == "celery"
Dynamic: license-file

![Logo](https://github.com/RDDLab/Django-GlobalConfig/raw/main/docs/static/img/logo.svg)

[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?style=for-the-badge)](https://opensource.org/licenses/MIT)
[![Version: 1.1.6](https://img.shields.io/badge/version-1.1.6-blue.svg?style=for-the-badge)](https://github.com/RDDLab/Django-GlobalConfig/releases/tag/1.1.6)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json&style=for-the-badge)](https://docs.astral.sh/ruff)
[![pyrefly](https://img.shields.io/endpoint?url=https://pyrefly.org/badge.json&style=for-the-badge)](https://pyrefly.org)
[![PyPI](https://img.shields.io/pypi/v/django-gc?style=for-the-badge)](https://pypi.org/project/django-gc/)
[![PyPI pyversions](https://img.shields.io/pypi/pyversions/django-gc.svg?style=for-the-badge)](https://pypi.python.org/pypi/django-gc/)
[![PyPI djversions](https://img.shields.io/pypi/djversions/django-gc.svg?style=for-the-badge)](https://pypi.org/project/django-gc/)
[![PyPI status](https://img.shields.io/pypi/status/django-gc.svg?style=for-the-badge)](https://pypi.python.org/pypi/django-gc)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/django-gc?style=for-the-badge)](https://pypistats.org/packages/django-gc)
[![PyPI - Types](https://img.shields.io/pypi/types/django-gc.svg?style=for-the-badge)](https://pypi.python.org/pypi/django-gc)

---

[![Tests](https://img.shields.io/github/actions/workflow/status/RDDLab/Django-GlobalConfig/testing.yml?branch=main&label=Tests)](https://github.com/RDDLab/Django-GlobalConfig/actions/workflows/testing.yml)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/RDDLab/Django-GlobalConfig/main.svg)](https://results.pre-commit.ci/latest/github/RDDLab/Django-GlobalConfig/main)

---

**Documentation**: <a href="https://django-gc.rdd-lab.com/" target="_blank">https://django-gc.rdd-lab.com/</a>

**Source Code**: <a href="https://github.com/RDDLab/Django-GlobalConfig" target="_blank">https://github.com/RDDLab/Django-GlobalConfig</a>

---

# 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

```bash
pip install 'django-gc>=1.1.6'
```

```python
INSTALLED_APPS = [
    'django_gc',
    'django.contrib.admin',
    # ...
]
```

Periodic refresh is optional:

```bash
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.

```python
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,
    ),
]
```

```bash
python manage.py migrate
python manage.py initialize_global_configs
```

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

```python
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](https://django-gc.rdd-lab.com/docs/getting-started/) · [Upgrade and operations](https://django-gc.rdd-lab.com/docs/operations/) · [Documentation deployment](.github/docs/README.md)

После создания схемы и при обновлении 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.
