Guides
Python (FastAPI)
Deploy a FastAPI app with uvicorn — requirements.txt, the start command, and common failures.
Create the app
- 1Apps → New app, pick the repository. A repo without package.json but with requirements.txt / pyapp.toml / .py files is detected as Python; a main.py makes it “Python service (FastAPI / Uvicorn)”.
- 2Choose Python Service and create the app.
- 3When main.py is detected, the start command is filled in as uvicorn main:app --host 0.0.0.0 --port $PORT. If your app object lives elsewhere, change it under Settings → Runtime configuration before the first deploy.
If detection did not recognise FastAPI (no main.py at the root), the app gets the generic gunicorn app:app --bind 0.0.0.0:$PORT, which does not run a FastAPI app. Set the uvicorn command yourself in that case.
What the repo needs
requirements.txt
fastapi
uvicornmain.py
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def root():
return {"ok": True}Settings
Install command: python -m venv .venv && .venv/bin/pip install -r requirements.txt
Build command: (empty)
Start command: uvicorn main:app --host 0.0.0.0 --port $PORT
Health check path: /- With only a pyapp.toml, detection uses .venv/bin/pip install . instead.
- Dependencies are installed into .venv inside the app, and .venv/bin is put on PATH at runtime, so uvicorn resolves. Output is unbuffered, so print() and logs show up in the runtime log right away.
- Read configuration with os.environ["DATABASE_URL"] or os.getenv("API_KEY"). Secrets are injected when the container starts; redeploy after changing one.
Common failures
- “Python start command couldn’t run” (uvicorn: not found) — uvicorn isn’t in requirements.txt, or the install command doesn’t create .venv. Use the install command above.
- “Health check returned 404 (app is running)” — FastAPI has no route at / unless you add one. Add it (or a /health route) or change the Health check path.
- “App didn’t respond on its assigned port” — uvicorn listens on 127.0.0.1:8000 unless told otherwise. Pass --host 0.0.0.0 --port $PORT.
- ModuleNotFoundError at start — a package your code imports is missing from requirements.txt, or requirements.txt isn’t in the Root directory.

