# Deploy FastAPI

FastAPI is detected from your dependencies and runs as a Python container on port `8000`. No Dockerfile needed - one is [generated](/platform/deployments/builds#dockerfiles-generated-or-your-own) unless the repo has its own.

## Serve it

Bind `0.0.0.0` on the routed [port](/create/build-settings#port) - `PORT` is set to it:

```bash
uvicorn app.main:app --host 0.0.0.0 --port $PORT
```

## Configuration and database

Read [environment variables](/platform/environment-variables#build-time-and-runtime) at startup - `os.environ`, or pydantic-settings, which maps them to a settings model. For the database, set `DATABASE_URL` from the [Credentials tab](/platform/databases/connect) - SQLAlchemy and the async drivers take the URL directly; keep `sslmode=require` in place.

Run Alembic migrations at startup or from your laptop against the same endpoint - see [Connect from your laptop](/platform/databases/connect#connect-from-your-laptop).

## Scaling

Async I/O suits the default [concurrency](/create/scaling#concurrency) of 80. CPU-bound endpoints (ML inference, heavy serialization) want it lower - `10`-`20` - or a bigger [size](/create/application-settings#size). [Scale to zero](/create/scaling#min-instances) covers idle time; connect to the database lazily so cold starts stay short.

## Related

- [Python](/platform/frameworks/python): The runtime's defaults for any Python app.
- [Connect an app](/platform/databases/connect): DATABASE_URL, TLS, per-environment databases.
- [Scaling](/create/scaling): Concurrency for CPU-bound endpoints.
