Skip to content

FastAPI

wireup.integration.fastapi

Classes

Functions

fastapi_request_factory()

Provide the current FastAPI request as a dependency.

Note that this requires the Wireup-FastAPI integration to be set up.

get_app_container(app)

Return the container associated with the given FastAPI application.

get_request_container()

When inside a request, returns the scoped container instance handling the current request.

setup(container, app)

Integrate Wireup with FastAPI.

Setup performs the following: * Injects dependencies into HTTP and WebSocket routes. * Creates a new container scope for each request, with a scoped lifetime matching the request duration. * Closes the Wireup container upon app shutdown using the lifespan context.

For more details, visit: https://maldoinc.github.io/wireup/latest/integrations/fastapi/

Note: To trigger lifespan events in the FastAPI test client, use the client as a context manager.

@pytest.fixture()
def client(app: FastAPI) -> Iterator[TestClient]:
    with TestClient(app) as client:
        yield client