Middleware¶
TenancyMiddleware ¶
Raw ASGI middleware that resolves the current tenant per request.
Sets the tenant on TenantContext at the start of every HTTP request
and restores the previous state at the end — even on error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
ASGIApp
|
The downstream ASGI application. |
required |
manager
|
Any
|
The configured :class: |
required |
excluded_paths
|
list[str] | None
|
List of URL path prefixes that bypass tenancy
resolution (e.g. |
None
|
Example::
Text Only
from fastapi_tenancy.middleware.tenancy import TenancyMiddleware
app.add_middleware(
TenancyMiddleware,
manager=manager,
excluded_paths=["/health", "/docs", "/openapi.json"],
)