> For the complete documentation index, see [llms.txt](/llms.txt).
> A full single-fetch corpus is available at [llms-full.txt](/llms-full.txt).
---
title: Integrate Python web frameworks
description: Add AGNT5 serverless routes to FastAPI, Starlette, Flask, Django, raw ASGI, or raw WSGI applications.
last_verified: 2026-07-31
---

The Python `ServerlessApp` exposes the same signed protocol through ASGI and WSGI. You can add AGNT5 to an existing Python web application without replacing its router, middleware, or deployment process.

FastAPI is the default scaffold. Use the Flask and Django adapters when you need to deploy an existing application as it is.

## Define the endpoint

Register components and create one protocol application:

```python
import os

from agnt5 import workflow
from agnt5.serverless import serve


@workflow
async def hello(ctx, name: str = "world") -> dict[str, str]:
    return {"message": f"hello {name}"}


agnt5_endpoint = serve(
    service_name="orders-api",
    service_version=os.getenv("GIT_SHA", "local"),
    signing_secret=lambda: os.getenv("AGNT5_SERVERLESS_SIGNING_SECRET"),
    workflows=[hello],
)
```

Pass explicit component lists when the process imports components that must not be public.

## Mount FastAPI or Starlette

```python
from fastapi import FastAPI

app = FastAPI()
agnt5_endpoint.mount_fastapi(app)
```

For Starlette, call `agnt5_endpoint.mount_starlette(app)`. Both methods add only `GET /.well-known/agnt5` and `POST /agnt5/invoke`.

## Mount Flask

```python
from flask import Flask

app = Flask(__name__)
agnt5_endpoint.mount_flask(app)
```

The Flask adapter keeps the existing WSGI application and registers two URL rules. Async AGNT5 workflows execute through the WSGI bridge.

## Mount Django

Export the endpoint from an application module, then extend the project URL configuration:

```python
from django.urls import include, path

from orders.agnt5_endpoint import agnt5_endpoint

urlpatterns = [
    path("api/", include("orders.urls")),
    *agnt5_endpoint.django_urlpatterns(),
]
```

`django_urlpatterns()` returns async Django views for the manifest and invoke routes.

## Use raw ASGI or WSGI

For a dedicated ASGI service, export the endpoint itself:

```python
app = agnt5_endpoint
```

Run it with an ASGI server:

```bash
uv run uvicorn orders.agnt5_endpoint:app --host 0.0.0.0 --port 8787
```

For a dedicated WSGI service, export the WSGI callable:

```python
application = agnt5_endpoint.wsgi_app
```


> The WSGI bridge creates an async execution context for each request. Prefer ASGI for new high-concurrency services. Use WSGI to preserve an existing Flask or Django deployment.


## Validate the routes

```bash
export AGNT5_SERVERLESS_SIGNING_SECRET="$(openssl rand -base64 32)"
agnt5 serverless validate http://127.0.0.1:8787
```

Validation fetches the manifest route and checks the component declarations before deployment.

## Next steps

- [Add AGNT5 to FastAPI](/docs/integrations/fastapi-serverless.md): generate and run the default Python scaffold.
- [Deploy to Cloud Run](/docs/integrations/cloud-run-serverless.md): deploy the Python ASGI service as an immutable revision.
- [Deploy to AWS Lambda](/docs/integrations/aws-lambda-serverless.md): package the FastAPI application with Lambda Web Adapter.
- [Serverless SDK reference](/docs/run/serverless-sdk-reference.md): compare Python, TypeScript, and Go durable APIs.
