FastAPI hosting

Publish a Python API without administering your own server. Run FastAPI with Uvicorn, check a preview release, and promote the version you have verified to production.

Last updated: 2026-10-26

From source code to a running service

Install the dependencies during the build. Set the application port to 8080, the health check path to /health, and the start command to the Uvicorn command below. Do not use --reload in production.

Deployment steps

1

Prepare the project

Add the example files or use your existing project. Install dependencies and check the start command locally before deploying.

2

Configure the application

Create an application in your workspace. Choose the source, start command, environment variables and resource allocation. Web services need a route port; polling bots can remain private.

3

Check the release

Deploy and inspect build and runtime logs. Test web routes on the preview URL. For a polling bot, send /start in Telegram and ensure another process is not using the token.

4

Publish and monitor

Promote a verified web release to production. Keep database migrations separate from application rollback. Monitor errors and resource use after the update.

A minimal project

These examples show application code and startup, not a preconfigured infrastructure template. Test and lock your dependencies before using them in production.

requirements.txt
fastapi>=0.115,<1
uvicorn>=0.30,<1
main.py
from fastapi import FastAPI

app = FastAPI()

@app.get("/health")
def health():
    return {"ok": True}

@app.get("/items/{item_id}")
def read_item(item_id: int):
    return {"item_id": item_id}
Start command
uvicorn main:app --host 0.0.0.0 --port 8080

Verify the API before promotion

Open /health, /items/1 and /docs on the preview address. Check authentication and database connectivity for your own routes before promoting the release. An HTTP health check alone does not verify business operations.

Separate request handling from durable work

FastAPI BackgroundTasks runs in the application process. If a task must survive restarts, use a persistent queue or a platform pipeline with explicit status and retries instead of relying on process-local work.

FAQ

Will Swagger UI work?

The example exposes /docs and /openapi.json using FastAPI defaults. Decide whether to expose these routes in production; configure authentication or disable them if the API documentation is private.

How do I connect PostgreSQL?

Set a database URL in the environment and read it from your database client. Run schema migrations as a separate controlled step. Promoting or rolling back application code does not roll back database changes.

How many Uvicorn workers should I start?

Start with one worker, as in this example, and measure memory use and request latency. Each extra worker loads application state separately. Increase workers or replicas only when the allocated CPU and memory can support them.

How much does hosting cost?

Check the current plans and available payment offers in Plan & billing. Size the application and its dependencies against the shared resource pool. Preview replicas and databases also consume resources; an idle application is not automatically free.