Package
Install one adapter.
Python Core and the compatible Django dependency are installed automatically. Django REST Framework remains optional.
pip install apirelio-djangoMiddleware
Add Apirelio after authentication.
# settings.py
import os
MIDDLEWARE = [
# Authentication must run before the Apirelio resolver.
"django.contrib.auth.middleware.AuthenticationMiddleware",
"apirelio_django.ApirelioMiddleware",
]
APIRELIO = {
"API_KEY": os.environ.get("APIRELIO_API_KEY", ""),
"ENDPOINT": os.environ.get("APIRELIO_ENDPOINT", "https://apirelio.com"),
"SERVICE": "billing-api",
"ENVIRONMENT": "production",
"RELEASE": os.environ.get("APIRELIO_RELEASE"),
"INCLUDE_ROUTES": ("/api/**",),
"EXCLUDE_ROUTES": ("/api/health/", "/api/internal/**"),
"RESOLVE_CUSTOMER": "accounts.apirelio.resolve_customer",
}B2B context
Resolve a stable customer.
A resolver can be a callable or dotted import path. It runs after the view, receives the completed HttpRequest and must return only bounded customer fields.
# accounts/apirelio.py
def resolve_customer(request):
account = getattr(request.user, "account", None)
if account is None:
return None
return {
"id": str(account.id),
"name": account.name,
"plan": account.plan,
}DRF support
No separate package required.
The same middleware instruments Django REST Framework views. For error responses it reads DRF's structured ErrorDetail.code, while never reading or sending the response body itself.
Lifecycle
Sync, async and fail-safe.
Synchronous and asynchronous Django handlers are supported. Capture only enqueues into a bounded background worker; process shutdown flushes pending events and analytics failures never alter the response or original exception.
Bodies, query strings, credentials, cookies, email addresses and client IP addresses are never included.