Skip to content

FastAPI Integration

  • Deep Integration


    Inject in endpoint handlers, middleware, decorators, and other request-path hooks.

    Learn more

  • Zero Runtime Overhead


    Inject dependencies with zero runtime overhead using Class-Based Handlers.

    Learn more

  • Background Tasks


    Inject dependencies into scheduled background callbacks via WireupTask.

    Learn more

  • Framework-Agnostic


    Share your service layer with CLI tools, background workers, and other frameworks.

Migrating from FastAPI Depends?

Evaluating Wireup for your FastAPI project? Check out the migration page which includes common pain points with FastAPI Depends and how to solve them with Wireup as well as a low-friction migration path:

Migrate from FastAPI Depends to Wireup.

Quick Start

This is the shortest path to a working FastAPI endpoint with Wireup injection.

main.py
from fastapi import FastAPI
import wireup
import wireup.integration.fastapi
from wireup import Injected, injectable


# 1. Define services
@injectable
class GreeterService:
    def greet(self, name: str) -> str:
        return f"Hello, {name}!"


# 2. Create container
container = wireup.create_async_container(injectables=[GreeterService])

app = FastAPI()


# 3. Use Injected[T] in routes for Wireup injection
@app.get("/")
async def greet(greeter: Injected[GreeterService]):
    return {"message": greeter.greet("World")}


# 4. Initialize Wireup integration
wireup.integration.fastapi.setup(container, app)
Best practice is to call setup(...) after routes are added.

Run the server with:

fastapi dev main.py

Detailed Guides

API Reference