Deploy a FastAPI app to production
FastAPI is the stack agents pick for 'a Python API'. It's also where serverless platforms hurt most — long-lived connections, ML model warm-up, background tasks. Launchmatic runs it as a normal uvicorn process in a container.
How detection works
A requirements.txt (or pyproject.toml/uv.lock) with fastapi. Nixpacks installs Python 3.11+, your dependencies, and needs a start command — set it to uvicorn (see snippet).
Build configuration & gotchas
Start command
uvicorn main:app --host 0.0.0.0 --port $PORT. Agents often write uvicorn.run(app) bound to 127.0.0.1 in a __main__ block — the CLI start command above overrides that correctly.
Workers
One container = start with --workers 2 for small instances, or scale replicas in the dashboard instead — Kubernetes-level scaling beats in-process workers for burst traffic.
Lockfiles
If the agent used uv or poetry, keep the lockfile in the repo — Nixpacks detects uv.lock/poetry.lock and installs with the right tool.
Model files
Large ML weights don't belong in git. Load from object storage at startup, or bake them into a custom Dockerfile layer if startup time matters.
Environment variables
DATABASE_URLStandard SQLAlchemy/asyncpg format, injected when you link Postgres.PORTInjected — always bind uvicorn to it.Set the start command once, then deploy:
lm init
lm deploy --start-cmd "uvicorn main:app --host 0.0.0.0 --port \$PORT"
# the override persists — future deploys are just: lm deployFAQ
Do FastAPI WebSockets and SSE work?+
Yes, natively — the container is a long-running uvicorn process, so WebSocket routes and streaming responses work without the workarounds serverless platforms need.
Ready to deploy?
Free to start. No credit card. Auto-SSL on custom domains, managed Postgres, and per-branch preview deploys included.
This guide is part of our complete vibe coding hosting guide — how to take any AI-built app to production.