Skip to main content

FastAPI integration adapters for mgf-common — request-id + exception translation + lifespan + webhooks (Svix HMAC) + IpAllowlist + run_test_app + DB-session helpers (via [sqlalchemy] extra). Sibling of mgf-common under the mgf.* namespace.

Project description

mgf-fastapi — FastAPI integration adapters for mgf-common

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 every FastAPI-specific adapter that previously lived under mgf.common.fastapi.* — extracted at mgf-common v0.28 / mgf-fastapi v0.1 per the federation split plan.

What this provides

Submodule What
mgf.fastapi bootstrap ↔ FastAPI lifespan; RequestIdMiddleware; ExceptionTranslationMiddleware; Depends() helpers (get_app_context, get_settings, get_request_id); setup_lifespan.
mgf.fastapi.webhooks Svix-shape HMAC webhook verification (HmacWebhookVerifier, WebhookHeaderSchema, SVIX_SCHEMA, verify_request).
mgf.fastapi.security IpAllowlist FastAPI dependency with proxy-trust opt-in.
mgf.fastapi.testing run_test_app async context manager — start uvicorn for a FastAPI app on a free port; yield base URL; clean shutdown.
mgf.fastapi.exceptions HmacVerificationError(HttpUnauthorized) and other framework-domain concrete leaves. (HTTP-01 hierarchy roots stay in mgf.common.exceptions.)

Install

pip install mgf-fastapi
# Or with the test-helper extra (uvicorn + httpx for run_test_app):
pip install 'mgf-fastapi[testing]'

Pulls in mgf-common and fastapi automatically.

Quick start

from fastapi import FastAPI, Request
from mgf.fastapi import (
    ExceptionTranslationMiddleware,
    RequestIdMiddleware,
    setup_lifespan,
)
from mgf.fastapi.webhooks import HmacWebhookVerifier, verify_request

app = FastAPI(lifespan=setup_lifespan(app_name="my-service", app_version="0.1.0"))
app.add_middleware(ExceptionTranslationMiddleware)
app.add_middleware(RequestIdMiddleware)

webhook = HmacWebhookVerifier(secret=settings.webhook_secret)

@app.post("/webhooks/clerk")
async def clerk_webhook(request: Request) -> dict:
    event_id, ts = await verify_request(request, webhook)
    payload = await request.json()
    # ... process the (now-trusted) payload ...
    return {"ok": True}

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.

Conformance: L2 per mgf-common/docs/standards/. Per-rule audit ledger: docs/inprogress/MGF_STANDARDS_CONFORMANCE.md. L2 means every federation MUST rule applies, evidenced by the tracker.

Status

🚧 Experimental — every public name is experimental per AP-09. Promotion to stable happens release-by-release as consumer feedback in FEEDBACK.md converges. The 0.x window applies. Pin tightly: mgf-fastapi = ">=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_fastapi-0.6.4.tar.gz (205.9 kB view details)

Uploaded Source

Built Distribution

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

mgf_fastapi-0.6.4-py3-none-any.whl (38.7 kB view details)

Uploaded Python 3

File details

Details for the file mgf_fastapi-0.6.4.tar.gz.

File metadata

  • Download URL: mgf_fastapi-0.6.4.tar.gz
  • Upload date:
  • Size: 205.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mgf_fastapi-0.6.4.tar.gz
Algorithm Hash digest
SHA256 8fe0735f939cd9c29aaa621a819796c7141eac9dfd1d5ce030d0c6b67be7de1f
MD5 d0ffe0429a731a261686e8498ba4ccc2
BLAKE2b-256 1a0edd301e8915a834217329504906e702a13c086cfd142495fbdf5799f8149d

See more details on using hashes here.

File details

Details for the file mgf_fastapi-0.6.4-py3-none-any.whl.

File metadata

  • Download URL: mgf_fastapi-0.6.4-py3-none-any.whl
  • Upload date:
  • Size: 38.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mgf_fastapi-0.6.4-py3-none-any.whl
Algorithm Hash digest
SHA256 94a93a5986b61becff566d770f91d109bfc760d6e9ac1d00fe028cf049ae0c25
MD5 6485f3ad59ac1267924b70a28d08d1d7
BLAKE2b-256 e53c1ee3b4832587d444aaac080298319c8658600bd97334c58de96e79df9065

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