Skip to main content

Django integration adapters for mgf-common — AppConfig + middleware (request-id, context) + JsonFormatter + DjangoSettingsBridge. Sibling of mgf-common under the mgf.* namespace.

Project description

mgf-django — Django integration adapters for mgf-common consumers

PyPI Python

Shape: Federation sibling of mgf-common. The current mgf-common pin window is shown in this package's PyPI metadata — sourced from pyproject.toml at release time, so this README can't go stale. (Per v2.6 DOC-01 / project-shape taxonomy. PAPER-38.)

Sibling of mgf-common under the mgf.* namespace. Houses the Django-specific adapters that previously lived under mgf.common.django.* — extracted at mgf-common v0.31 / mgf-django v0.1 per the federation split plan.

What this provides

Submodule What
mgf.django MgfCommonConfig — Django AppConfig that runs mgf.common.bootstrap() once at app-registry build. MgfRequestIdMiddleware + MgfContextMiddleware — sync-mode middleware sharing the same contextvar as mgf.fastapi.RequestIdMiddleware for cross-framework request-id correlation. JsonFormatter — no-arg wrapper for Django's LOGGING['formatters'] '()': '...' factory syntax. DjangoSettingsBridge — read-only BaseAppSettings view over django.conf.settings (so mgf-common explain works for Django apps).

Five public names. The closed-box adapter shape: your manage.py, settings.py, and views remain unchanged; you add one entry to INSTALLED_APPS and two to MIDDLEWARE.

Install

pip install mgf-django

Pulls in mgf-common + django>=4.2 automatically.

Quick start — typical Django settings.py addition

# settings.py
INSTALLED_APPS = [
    # ... your apps ...
    "mgf.django",
]

MIDDLEWARE = [
    "mgf.django.MgfRequestIdMiddleware",  # earliest
    "mgf.django.MgfContextMiddleware",
    # ... your other middleware ...
]

LOGGING = {
    "version": 1,
    "formatters": {
        "json": {"()": "mgf.django.JsonFormatter"},
    },
    "handlers": {
        "console": {
            "class": "logging.StreamHandler",
            "formatter": "json",
        },
    },
    "root": {"handlers": ["console"], "level": "INFO"},
}

# Optional — both default to None (auto-derived from package metadata)
MGF_COMMON_APP_NAME = "myapp"
MGF_COMMON_APP_VERSION = "1.0.0"

That's the entire integration. The AppConfig calls mgf.common.bootstrap() once when Django boots; the middlewares carry the per-request state; the formatter routes through the standard mgf-common redaction + OTel correlation pipeline.

What you get for free

  • One bootstrap call — identity, structured logging, OTel wiring, crash-reporting hooks installed exactly once per process.
  • Per-request X-Request-Id — generated as UUID4 if missing, forwarded if present. Same contextvar as mgf.fastapi so a Django-to-FastAPI internal RPC propagates the request id end-to-end.
  • AppContext on request.mgf_context — views can read identity
    • settings without touching globals.
  • Default-on log redaction — secret-shaped fields scrubbed by the formatter before any sink sees them (no per-call wrapper needed).
  • mgf-common explain worksDjangoSettingsBridge.from_django() exposes a curated, typed view of django.conf.settings for the diagnostic CLI.

App label note

The Django app label is "mgf_django" (Django labels can't contain dots). Renamed at the v0.31 sibling extraction from "mgf_common" (its name when the module lived under mgf.common.django in mgf-common ≤ v0.30). Consumer config that hardcoded the old "mgf_common" label MUST update — typical references are in AppConfig.get_app_config("mgf_common") calls or migration table- prefix configs.

Documentation

For the federation-wide engineering standards (DESIGN_PRINCIPLES, ERROR_HANDLING, SECURITY, etc.) see mgf-common/docs/standards/. This sibling inherits them by reference; the standards source-of-truth lives in mgf-common.

Status

🚧 Experimental — every public name is experimental per AP-09. Promotion to stable happens release-by-release as consumer feedback in mgf-common/FEEDBACK.md converges. The 0.x window applies. Pin tightly: mgf-django = ">=0.X.0,<0.Y".

Cross-references

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mgf_django-0.4.1.tar.gz (138.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mgf_django-0.4.1-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file mgf_django-0.4.1.tar.gz.

File metadata

  • Download URL: mgf_django-0.4.1.tar.gz
  • Upload date:
  • Size: 138.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for mgf_django-0.4.1.tar.gz
Algorithm Hash digest
SHA256 e8c7d823fa2bd60744a1ebb5d8a99b1444ebdb96f1de42d299131d3cdd38cc5c
MD5 a19427af1408100771cfdeda8a88164e
BLAKE2b-256 b4fba348156f8d471a4328941dbd9f04c69086c850ededa84423d4c587ce6858

See more details on using hashes here.

File details

Details for the file mgf_django-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: mgf_django-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 19.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for mgf_django-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e6438a941c930d5ec9e8889629b999426398f78e12be9c5af489204e548f7dc4
MD5 beec08e0d77af81976ccbdcfcced5223
BLAKE2b-256 4e4a8498f4473dcd28a905769fccc402dacfc85bf05e38aca808f1b8fee820a7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page