Deploy FastAPI on Temps

Temps detects a FastAPI app from requirements.txt or pyproject.toml, finds your FastAPI() object and starts it with Uvicorn on $PORT behind automatic HTTPS. A linked PostgreSQL database arrives as POSTGRES_URL; swap its scheme to postgresql+asyncpg:// for async SQLAlchemy, and run Alembic migrations yourself.

This guide describes how the nightly release channel builds your app, using the Autopack builder. Beta (v0.1.0-beta.56) also builds with Autopack, but some details below may differ. Earlier releases and the stable channel build with Nixpacks and behave differently. To run nightly, see Release channels.

For an overview of self-hosting FastAPI, including costs, see Deploy FastAPI to your own server. Every framework and the preset it needs is listed under Supported platforms; for a full Django app, see Deploy Django.


Quickstart

From your project root, deploy with your preferred package manager:

npx @temps-sdk/cli up --preset python

Temps installs your dependencies and looks for FastAPI( (or Starlette() in main.py, app.py, asgi.py, wsgi.py or server.py. When it finds one, it starts your app with uvicorn <module>:app --host 0.0.0.0 --port $PORT, and adds Uvicorn to the build if your dependencies don't include it. Your app object must be named app; otherwise, set the start command in a Procfile. The Python version comes from .python-version, runtime.txt or requires-python in pyproject.toml, and defaults to 3.12.

Once running, FastAPI serves its /docs (Swagger UI) and /redoc endpoints as usual.


What Temps handles automatically

FeatureHow Temps handles it
Installuv, Poetry, Pipenv or pip, chosen from your lockfile or manifest (for example pip install -r requirements.txt)
ASGI serverUvicorn with its default settings (one worker); set your own command in a Procfile
OpenAPI/docs and /redoc, served by FastAPI itself
MigrationsNot run automatically — see Alembic Migrations
HTTPSLet's Encrypt certificate, auto-renewed
PortPORT env var injected, defaults to 8000
WebSocketsFully supported via Uvicorn

Procfile

To control the start command (for example to run more workers), add a Procfile at the project root. Its web: line replaces the command Temps would otherwise generate. Temps then no longer adds Uvicorn for you, so make sure uvicorn is in your dependencies:

web: uvicorn main:app --host 0.0.0.0 --port $PORT --workers 4

Alembic Migrations

Temps doesn't run migrations for you, and has no deploy hooks. Run alembic upgrade head yourself after a deploy that changes the schema, for example from your CI pipeline, or inside the running container as shown for Django migrations.


Environment Variables

npx @temps-sdk/cli environments vars set SECRET_KEY "your-secret-key" -e production

Managed PostgreSQL and Redis

Create PostgreSQL or Redis under Databases → Create database, then link it from your project's Databases page. Temps injects POSTGRES_URL and REDIS_URL (plus the individual host, port and credential variables) automatically.

POSTGRES_URL starts with postgresql://. For SQLAlchemy with asyncpg, swap the scheme in code:

import os

DATABASE_URL = os.environ["POSTGRES_URL"].replace("postgresql://", "postgresql+asyncpg://", 1)

Platform behavior

These rules apply to every app deployed on Temps, regardless of framework.

The one requirement: your app must listen on the port in the PORT environment variable and bind to 0.0.0.0 — not localhost or 127.0.0.1. Temps runs your app in a container and routes traffic from the host, so an app bound to localhost only accepts connections from inside the container and will fail its health check.

Health checks

After your container starts, Temps sends HTTP GET requests to verify it is healthy before routing traffic to it.

  • Path: / (the root of your application) by default
  • Success: 2 consecutive responses with a 2xx, 3xx, 404 or 405 status code
  • Timeout: 300 seconds (5 minutes) for the app to become healthy, fixed in v0.1.0-beta.56. If the app answers with error responses (other 4xx, or 5xx) for 60 seconds in a row, the deployment fails sooner. From the next release the timeout is configurable from 30 to 3600 seconds under Project → Settings → Build & deploy
  • Retry interval: 2 seconds between successful checks, 5 seconds after an error response or a failed connection

Connection errors and other 4xx or 5xx responses are retried until the timeout; if the app hasn't passed by then, the deployment fails. The check runs once, at deploy time. To check a different path, add a .temps.yaml to your repository root:

.temps.yaml
health:
  path: /health

Only path is used. Other health fields (status, interval, timeout, retries) are accepted but currently have no effect.

Add a dedicated /health endpoint that returns a simple 200. This avoids issues where / requires authentication or returns a redirect.

Auto-injected environment variables

Temps injects these variables into every deployment automatically:

VariableValueDescription
PORTResolved portThe port your app must listen on
HOST0.0.0.0Bind address
SENTRY_DSNAuto-generatedError tracking endpoint
TEMPS_API_URLYour Temps URLPlatform API endpoint
TEMPS_API_TOKENDeployment tokenAuthentication for Temps SDKs
OTEL_EXPORTER_OTLP_ENDPOINTYour Temps OTLP URLOpenTelemetry trace collection
OTEL_SERVICE_NAMEProject nameService identifier for traces

You do not need to configure these manually. They are available in process.env (Node.js), os.environ (Python), os.Getenv (Go), and the equivalent in other languages.


Next Steps

Last updated

Was this page helpful?