# Deploy FastAPI on forkrail

> Run ASGI FastAPI services on Python 3.12–3.14 arm64 with up to 10 concurrent requests per warm worker, zero Lambda adapter wrappers, and automatic dependency caching.

- Framework: FastAPI
- Category: APIs & backends
- Status: Production ready
- Adapter / Preset: None (native ASGI via uvicorn)
- Runtime: Python 3.13 arm64 (also 3.12 & 3.14)
- Detection: app.py / main.py / api/main.py or pyproject.toml
- Memory: 640 MB default (adjustable per project)
- URL: https://www.forkrail.com/frameworks/fastapi

## Capabilities

| Capability | Support | Details |
| --- | --- | --- |
| 10× concurrent ASGI | Supported | Up to 10 concurrent requests share one warm uvicorn worker |
| Dependency formats | Supported | pyproject.toml + uv.lock, Pipfile.lock, or requirements.txt |
| Zero wrapper code | Supported | No Mangum or AWS Lambda handler boilerplate needed |
| Streaming & SSE | Supported | StreamingResponse and Server-Sent Events stream end to end |

## 1. Project layout & entrypoint

forkrail automatically locates `app` in `app.py`, `index.py`, `server.py`, `main.py`, or `asgi.py` at the project root or under `src/`, `app/`, or `api/` — or specify an explicit module in `pyproject.toml`:

**api/main.py**

```python
from fastapi import FastAPI
from fastapi.middleware.gzip import GZipMiddleware

app = FastAPI()
app.add_middleware(GZipMiddleware, minimum_size=1000)

@app.get('/health')
async def health():
    return {'status': 'ok'}
```

**pyproject.toml**

```toml
[project]
name = "billing-api"
requires-python = ">=3.13"
dependencies = [
  "fastapi>=0.115",
  "httpx>=0.28",
]

[tool.vercel]
entrypoint = "api.main:app"
```

Pin your Python version in `.python-version` or `requires-python` (`3.12`, `3.13`, or `3.14`; defaults to `3.13`). Dependencies install for Linux arm64 manylinux wheels inside the builder and cache between deploys.

## 2. Deploy & tail logs

**Deploy FastAPI and inspect live traffic**

```bash
# Deploy a preview
forkrail deploy

# Ship to production
forkrail deploy --prod

# Stream requests, Python print/logging output, and outgoing HTTP calls
forkrail logs billing-api --app --follow
```

## 3. Concurrent compute & AWS connectivity

- **Async I/O shines:** Because uvicorn serves up to 10 concurrent streams per Lambda worker, FastAPI endpoints waiting on Postgres, Redis, or external APIs pay for one warm worker instead of ten.
- **Need strict isolation?** Set `"fluid": false` in `vercel.json` (or `forkrail project billing-api --concurrent false`) for one request per worker.
- **Keep startup fast:** Run slow warm-up work in FastAPI lifespan background tasks rather than blocking import time.
- **Private AWS services:** Assign an IAM role (`--role`) for boto3 without keys, or expose internal RDS/Postgres targets via `--egress`.

## Related documentation

- [Concurrent compute](https://www.forkrail.com/docs/concurrent-compute.md)
- [Logs & observability](https://www.forkrail.com/docs/logs-and-observability.md)
- [Environment variables](https://www.forkrail.com/docs/environment-variables.md)
