apipilot.wsgi module

WSGI middleware implementing the same ApiPilot pipeline for Flask, Django (WSGI), Bottle, Pyramid, and any WSGI framework.

ApiPilotWSGIMiddleware — WSGI binding for ApiPilot.

Pure WSGI middleware implementing the same pipeline as the ASGI adapter: correlation → rate-limit → content-negotiation → origin → fetch-metadata → CSRF → pagination → exception mapping.

Works with Flask, Django (WSGI), Bottle, Pyramid, and any WSGI framework:

# Flask
app.wsgi_app = ApiPilotWSGIMiddleware(app.wsgi_app, options=...)

# Django (WSGI)
application = ApiPilotWSGIMiddleware(get_wsgi_application(), options=...)

# Raw WSGI
application = ApiPilotWSGIMiddleware(my_wsgi_app, options=...)

The middleware builds an ASGI-compatible scope dict from the WSGI environ, so the same DefaultCsrfBindingResolver extractors and rate_limit.key_extractor callables work unchanged — they receive a dict with type, method, path, query_string, headers (list of (bytes, bytes)), and client.

Parsed pagination is stored on environ["apipilot.pagination"] (mirrors scope["apipilot.pagination"] in the ASGI adapter).

class apipilot.wsgi.ApiPilotWSGIMiddleware(app: Any, options: ApiPilotOptions | None = None, csrf_key_ring: CsrfKeyRing | None = None, csrf_binding: DefaultCsrfBindingResolver | None = None)[source]

Bases: object

WSGI middleware applying the ApiPilot request pipeline.

Usage:

application = ApiPilotWSGIMiddleware(app, options=ApiPilotOptions(...))