Deploy / FastAPI

Deploy FastAPI to Your Own Server

To deploy FastAPI to your own server, install Temps on a Linux VPS and run up --preset python from the project root. Temps finds your FastAPI( app, starts it with Uvicorn on the port it injects and serves it over automatic HTTPS; /docs and /redoc work as usual. You link PostgreSQL and run Alembic migrations yourself.

Last updated

Detection

Auto-detected from requirements.txt, pyproject.toml, Pipfile or setup.py: Temps picks the Python preset, so up needs no flag.

How to deploy FastAPI with Temps

Commands run on your machine unless they say otherwise. The CLI runs with bunx or npx.

  1. 1

    Install Temps on a Linux server

    On a VPS with at least 2 CPU cores and 4 GB of RAM, download the installer, read it, then run it. It installs Docker if needed, the Temps binary and its database, and asks how the console is reached: an sslip.io address or your own domain.

    curl -fsSL https://temps.sh/deploy.sh -o deploy.sh
    less deploy.sh
    bash deploy.sh
  2. 2

    Log in from your machine

    Point the CLI at your Temps console. It opens a browser to approve the login.

    bunx @temps-sdk/cli login https://console.example.com
  3. 3

    Add a Procfile if your app isn't in a top-level module

    An app in app/main.py, or one not named app, needs its own start command. With a Procfile, Temps no longer adds Uvicorn for you, so list uvicorn in your dependencies.

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

    Read the database URL Temps injects

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

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

    Add a health route

    Point health.path at it in .temps.yaml so the first deploy passes before the tables exist.

    main.py
    @app.get("/health")
    async def health():
        return {"status": "ok"}
  6. 6

    Deploy FastAPI

    From the project root, run up. If the directory isn't linked to a project yet, it walks you through creating one first. For a project created from a Git repository, pushes to the tracked branch deploy automatically.

    bunx @temps-sdk/cli up
  7. 7

    Create and link a PostgreSQL database

    Temps doesn't create a database for you. Create one, then link it to the project (or use Databases → Create database in the dashboard). Linking injects POSTGRES_URL plus POSTGRES_HOST, POSTGRES_PORT, POSTGRES_DB, POSTGRES_USER and POSTGRES_PASSWORD into the next deployment. It doesn't inject DATABASE_URL.

    bunx @temps-sdk/cli services create -t postgres -n my-fastapi-app-db
    bunx @temps-sdk/cli services link --id <service-id> -p my-fastapi-app
  8. 8

    Run migrations after deploys that change the schema

    Temps doesn't run migrations and has no release phase. Find the running container, then run the migration in it over SSH, by hand or from CI right after the deploy step. Don't add it to the start command: restarts and replicas would run it more than once.

    bunx @temps-sdk/cli projects show -p my-fastapi-app --json   # note the numeric "id"
    bunx @temps-sdk/cli containers list -p <project-id>     # note the container_name
    ssh your-server 'docker exec <container_name> alembic upgrade head'
  9. 9

    Send errors to Temps

    Temps injects SENTRY_DSN, pointing at the project's built-in error tracking, so the standard Sentry SDK needs no other configuration. Add sentry-sdk[fastapi] to your dependencies.

    main.py
    import os
    import sentry_sdk
    
    sentry_sdk.init(dsn=os.environ.get("SENTRY_DSN"))

How Temps builds and runs FastAPI

Every app runs in a Docker container on your server, behind the Temps proxy. Before traffic switches to a new deployment, Temps health-checks it; if the check fails, the deployment is marked failed and the current version keeps serving.

Entry pointFastAPI( or Starlette( in main.py, app.py, asgi.py, wsgi.py or server.py; the object must be named app
Startuvicorn <module>:app --host 0.0.0.0 --port $PORT with one worker; a Procfile web: line replaces it
PythonFrom .python-version, runtime.txt or requires-python; defaults to 3.12
API docs/docs (Swagger UI) and /redoc, served by FastAPI itself
MigrationsNot run by Temps; run alembic upgrade head yourself

What works with FastAPI on Temps

  • Uvicorn started for you, one worker by default
  • More workers with a Procfile web: line
  • OpenAPI /docs and /redoc served as usual
  • WebSockets through the reverse proxy
  • Managed PostgreSQL and Redis you link
  • Health check before each cutover

Managed services for FastAPI

Temps runs these services on your server. Create one, link it to the project, and its connection variables reach the next deployment. Set up managed services.

PostgreSQL

Injects POSTGRES_URL (a postgresql:// URL) once linked

Redis

Injects REDIS_URL for caching and task queues

Environment variables for FastAPI

Set your own with environments vars set or in the project settings; values are encrypted at rest.

VariableWhat it does
POSTGRES_URLInjected when PostgreSQL is linked
REDIS_URLInjected when Redis is linked
SENTRY_DSNInjected by Temps for the built-in error tracking
SECRET_KEYYour own secrets, set per environment
PORTSet by Temps; Uvicorn binds to it

What it costs to self-host FastAPI

Temps is free to self-host under MIT / Apache 2.0, with no per-seat fee and nothing metered, so hosting FastAPI costs what the server costs. A Hetzner CX23 (2 shared vCPU, 4 GB RAM, 40 GB NVMe, 20 TB traffic) meets the minimum Temps needs and is €5.49/month excluding VAT, plus €0.50/month for an IPv4 address; Hetzner sells it in Germany and Finland only. Prices checked October 10, 2026.

TempsFree and open source (MIT / Apache 2.0)
ServerHetzner CX23: €5.49/month excluding VAT, plus €0.50/month for IPv4
What FastAPI runsOne Uvicorn container, plus the managed PostgreSQL and Redis you link, on the same server.
ObservabilityWeb analytics, error tracking, session replay and uptime monitoring are included and run on the same server
Temps PremiumOptional: $399 per organisation per month for SAML SSO, SCIM, custom roles, approval gates and a tamper-evident audit log

For one to three production apps, the server guide recommends 4 vCPU and 8 GB RAM: a Hetzner CX33 is €8.49/month excluding VAT. Any Linux VPS that meets the minimum works; sizes and other providers are in Choosing a server. For what the same app costs on Railway, see Temps vs Railway.

FastAPI on Temps: frequently asked questions

How do I run more Uvicorn workers on Temps?

Add a Procfile with web: uvicorn main:app --host 0.0.0.0 --port $PORT --workers 4. To spread load across containers instead, raise the replica count with bunx @temps-sdk/cli environments scale -p my-fastapi-app -r 2.

Does Temps run Alembic migrations on deploy?

No. Temps has no deploy hooks. Run alembic upgrade head after a deploy that changes the schema, from CI or with docker exec in the running container over SSH.

Do FastAPI background tasks work on Temps?

BackgroundTasks run inside the Uvicorn process, so they work as normal but stop if the container restarts. For durable jobs, use a queue consumer that runs outside the web process; Temps doesn't run Procfile worker: lines.

Included with every Temps project

Deployments, analytics, error tracking, session replay and uptime monitoring run in the same self-hosted platform, so your FastAPI app doesn't need separate subscriptions for them.

Automatic HTTPS

Let's Encrypt certificates for every domain, issued and renewed for you.

Preview deployments

Turn on preview environments and each branch gets its own URL on your domain.

Web analytics

First-party analytics stored on your server. Add the React provider or a script tag.

Error tracking

Sentry-compatible: any Sentry SDK can report to the SENTRY_DSN Temps injects.

Session replay

Off by default. When on, it records the DOM with every input masked.

Uptime monitoring

HTTP monitors for your apps, with alerts through your notification channels.

Related guides

Deploy another framework

Deploy FastAPI on a server you own

Temps is free and open source to self-host (MIT / Apache 2.0). You pay only for the server.