FastAPI integration adapters for mgf-common — request-id + exception translation + lifespan + webhooks (Svix HMAC) + IpAllowlist + run_test_app. Sibling of mgf-common under the mgf.* namespace.
Project description
mgf-fastapi — FastAPI integration adapters for mgf-common
Sibling of
mgf-commonunder themgf.*namespace. Houses every FastAPI-specific adapter that previously lived undermgf.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
docs/recipes/fastapi.md— full FastAPI service walkthrough.docs/recipes/webhooks.md— HMAC webhook verification.docs/cutover/v0.1.0.md— maiden voyage migration story (the v0.28 split).PUBLIC_API.md— full public surface contract.CHANGELOG.md— release history.
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 FEEDBACK.md converges. The 0.x window applies.
Pin tightly: mgf-fastapi = ">=0.X.0,<0.Y".
Cross-references
- Filing process for sharp edges: open an entry on
mgf-common/FEEDBACK.mdwith[mgf-fastapi]prefix, OR file directly on this repo's Issues → maintainer mirrors into the canonical FEEDBACK.md. - Federation pattern:
mgf-common/docs/design/federation.md. - The split that created this sibling:
mgf-common/docs/release/federation_roadmap.md.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mgf_fastapi-0.1.0.tar.gz.
File metadata
- Download URL: mgf_fastapi-0.1.0.tar.gz
- Upload date:
- Size: 39.2 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b288e7c63c6b7e8271b58e9276d27b26c0f9ae519e0f75050ec5f9ba71ceb5b
|
|
| MD5 |
86d0c4d1affbe38b67b94eaaefa55380
|
|
| BLAKE2b-256 |
d8bece953d511185ec8d19b720f752aaa4001b9099edf1f1657e645c8848a9e4
|
File details
Details for the file mgf_fastapi-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mgf_fastapi-0.1.0-py3-none-any.whl
- Upload date:
- Size: 22.3 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b639bf6f66b1b26488664189aaca6319fdfe536be4d28216cba07c9723f67ee
|
|
| MD5 |
16740e3db08eec4756ee7c8aa0ca90ac
|
|
| BLAKE2b-256 |
285022f31d8fc59ea7c32a0d4c24d8e54e963260792311b79cf34bf38e590d48
|