Skip to content
FastAPI deploy guide

Deploy FastAPI in Europe

Run a FastAPI service on EU infrastructure: HostStack builds the Python side, you give it one start command, and a managed Postgres arrives as DATABASE_URL.

There is no FastAPI preset, and a FastAPI app does not need one. HostStack builds it as a Python project — the version from your project files, dependencies with pip — and all you add is the command that starts uvicorn on the port HostStack injects. Everything runs in Helsinki under a Danish company, which matters when the API is what your European customers’ data passes through.

What HostStack detects and builds

  • Python is recognised from requirements.txt or pyproject.toml. FastAPI itself is not detected, so set the start command — the Python default is python main.py.
  • Dependencies install with pip install -r requirements.txt, or pip install . when there is only a pyproject.toml.
  • The Python version comes from .python-version, runtime.txt, .tool-versions, Pipfile, requires-python or Poetry’s python dependency; with none, the newest release.
  • There is no build step by default. Add one in hoststack.yaml if you need it.
  • The official slim Python image is the base, and the start command runs through a shell, so $PORT in it is expanded.
StepDefault when you leave it empty
Installpip install -r requirements.txt (or pip install .)
Build— (none)
Startpython main.py — set your own
PortPORT=3000 unless you set another

uvicorn has to be installed — fastapi[standard] brings it — and must bind 0.0.0.0, not its default 127.0.0.1.

hoststack.yaml for FastAPI

Optional. Commit it next to your code and every deploy applies it; leave a key out and the service keeps its dashboard value. It configures a service that already exists — it never creates one. The full schema and hoststack validate are in the docs.

hoststack.yaml
services:
  api:
    install:
      command: pip install -r requirements.txt
    start:
      command: uvicorn app.main:app --host 0.0.0.0 --port $PORT --workers 2
    healthCheck:
      path: /health
    env:
      PYTHONUNBUFFERED: "1"

app.main:app is the module and the FastAPI instance — adjust it to your layout. Add a GET /health route that returns 200, since a FastAPI app has no / by default.

Database and environment variables

Linking a managed Postgres injects DATABASE_URL as postgresql://…, which psycopg and SQLAlchemy’s sync engine take as it is. For async SQLAlchemy, swap the scheme in code: os.environ["DATABASE_URL"].replace("postgresql://", "postgresql+asyncpg://", 1).

bash
hoststack db create --project prj_... --name app-db --engine postgres --plan micro
hoststack db link db_... --service svc_...
hoststack env set svc_... JWT_SECRET=... --secret
hoststack services update svc_... --pre-deploy-command "alembic upgrade head"

Secrets belong on the service, not in the file — see environment variables and databases.

Deploy FastAPI step by step

  1. 1Add uvicorn (or fastapi[standard]) to your requirements and a GET /health route to the app.
  2. 2Create a web service from your repository, in the dashboard or with hoststack services create --name api --type web_service --project prj_... --repo acme/api.
  3. 3Commit the hoststack.yaml above with your module path in the start command.
  4. 4Create a managed Postgres and link it; DATABASE_URL is injected on the next deploy.
  5. 5Set alembic upgrade head as the pre-deploy command, so the schema is current before traffic switches.
  6. 6Push to deploy. The interactive docs are live at /docs on the service’s URL.

Hosted in Europe, by a European company

FastAPI is a common choice for the API in front of a model or a data pipeline — exactly where personal data passes through. Running it, its database and its logs in an EU region under an EU company keeps that traffic out of US jurisdiction entirely.

Every service, database and backup runs in Helsinki, Finland, on Hetzner, and HostStack is operated by MICCI, a Danish company — so the US CLOUD Act has no hold on it, the GDPR data processing agreement is signed at signup on every plan, and the invoice is in EUR. Why that differs from a US platform's EU region is on EU data residency.

Things that catch people out

uvicorn binds 127.0.0.1 unless told otherwise.

Pass --host 0.0.0.0. Without it the server starts, the health check never reaches it, and the deploy fails while the previous version keeps serving.

Poetry and uv lockfiles are not used for the install.

With no requirements.txt, the build runs pip install . from pyproject.toml. To install exactly what your lockfile pins, export it with uv export or poetry export to requirements.txt, or set your own install command.

Background work outlives a request.

FastAPI’s BackgroundTasks run inside the web process and stop with it on a deploy. For anything longer, run a Worker service from the same repo with its own start command.

Frequently asked questions

How do I deploy FastAPI in Europe?

Push the repo to HostStack, which builds it as a Python app in Helsinki, Finland, and set the start command to uvicorn app.main:app --host 0.0.0.0 --port $PORT. Link a managed Postgres for DATABASE_URL and run Alembic as the pre-deploy command.

Does HostStack detect FastAPI automatically?

It detects Python from requirements.txt or pyproject.toml and installs your dependencies, but it does not detect FastAPI or choose a server for it. Set the start command once — in the service’s settings or in hoststack.yaml — and every deploy uses it.

Can I use Gunicorn with Uvicorn workers?

Yes. Any start command works, for example gunicorn app.main:app -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:$PORT --workers 2, as long as gunicorn and uvicorn are in your requirements.

How much does it cost to host a FastAPI service?

The free tier runs one Nano service (256 MB) with a Starter Postgres and no card; it sleeps after 60 minutes without traffic. Always-on services start at €1/month, and Micro (512 MB, €5/month) suits a typical API.

Other stacks

All guides are on the deploy guides index. Moving an existing FastAPI app? The Render, Railway and Fly.io guides have the cutover order.

Deploy your FastAPI app

Free tier, no card: one service and one Postgres, in the EU.

Essential cookies only — for login sessions. No tracking. Details