# How to deploy a FastAPI app with Postgres for free.

URL: https://antideploy.com/blog/how-to-deploy-a-fastapi-app-with-postgres-for-free

FastAPI deploys with one sentence. It needs uvicorn in your requirements, and it can use the free Postgres database Antideploy creates.

## At a glance

- **uvicorn**: Started with your module and the PORT variable
- **Postgres**: 1 database on the Free plan
- **Alembic**: Migrations run before release
- **Free plan**: 1 live app with a server

Published 7 October 2026. Facts checked 7 October 2026. 3 min read.

## The short answer

To deploy a FastAPI app with Postgres for free, give your coding agent the sentence below. Antideploy finds FastAPI in your requirements, starts it with `uvicorn`, and creates a Postgres database if your code needs one. The Free plan includes 1 live app with a server and 1 Postgres database, with no card. Your requirements must list `uvicorn`.

> **Say this to your coding agent**
>
> Set this project up to deploy on Antideploy. Fetch https://antideploy.com/agent.md and follow it.

## What Antideploy detects

- **FastAPI.** Detected from `fastapi` in `requirements.txt` or `pyproject.toml`. The shallowest one is used.
- **The start command.** `uvicorn module:app --host 0.0.0.0 --port $PORT`. The module is found by looking for the file that contains `app = FastAPI(`. If none is found, it uses `main`.
- **The port.** It starts the app with `PORT` set, and the start command uses it.
- **The Python version.** From `.python-version`, `runtime.txt` or `requires-python` in `pyproject.toml`.
- **The database.** A `psycopg` or `asyncpg` requirement means Postgres, and SQLAlchemy is recognised too. With Alembic in your requirements, `alembic upgrade head` runs before the new version goes live.

## What your project needs

**requirements.txt**

```
fastapi
uvicorn
psycopg[binary]
sqlalchemy
alembic
```

**main.py**

```
import os
from fastapi import FastAPI
from sqlalchemy import create_engine

app = FastAPI()
engine = create_engine(os.environ["DATABASE_URL"])

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

If `uvicorn` is not in your requirements, Antideploy warns you that the app will build but will not start. Add it before you deploy. You do not need to set the host or port in code, because the start command passes `0.0.0.0` and `PORT`.

## Step by step

### 1. Check the requirements

`fastapi` and `uvicorn` are listed, and the database is read from `DATABASE_URL`.

### 2. Paste the sentence and approve one link

Your agent creates the app and the database, writes the connection details into your `.env` without printing them, and builds against the real database.

### 3. Deploy and open the link

Antideploy installs your requirements, runs `alembic upgrade head` if you use Alembic, starts the app and checks that it answers. Your agent tells you the address. FastAPI's `/docs` page is available on it.

## Common problems

- **The app builds but never starts.** `uvicorn` is missing from your requirements. See [never started listening](https://antideploy.com/blog/your-app-built-successfully-but-never-started-listening-on-its-port).
- **No matching version.** A pinned package has no build for the Python version in use. Pin another Python in `.python-version`. See [Could not find a version that satisfies the requirement](https://antideploy.com/blog/could-not-find-a-version-that-satisfies-the-requirement).
- **No module named.** The code imports a package that is not in your requirements. See [ModuleNotFoundError](https://antideploy.com/blog/modulenotfounderror-no-module-named).
- **A SQLite file resets.** The disk is replaced on every deploy. Use Postgres.

## Here's where it stops.

A platform that only tells you what it is good at is one you find the edges of in production. These are the ones to know before your first deploy.

### Apps sleep when idle

On every plan, an app nobody is using goes to sleep and the next visit wakes it. The first request took 2.9 to 13.9 seconds in our measurements, depending on the stack. There are no always-on workers, so use a cron job or a webhook for background work.

### One instance, no previews

Each app is one instance with 1 shared vCPU and 1 GB of memory, and a Java app gets 1 dedicated vCPU and 2 GB. There are no preview deployments and no per-branch URLs.

### The disk forgets

Anything written to local disk is gone on the next deploy. Apps that speak S3 get a bucket instead.

### 10 deploys a month on Free

Only successful deploys of apps with a server count. Static sites never do, and a failed deploy is free.

## FastAPI questions, answered.

Anything else? Write to us and a person answers.

[support@antideploy.com](mailto:support@antideploy.com)

### Is it really free?

The Free plan includes 1 live app with a server, 10 successful deploys a month and 1 Postgres database. It needs no card and has no trial clock. Failed deploys are free.

### Why is the first request slow?

Apps sleep when idle. Measured on 19 September 2026, the first request after sleeping took 5.1 to 9.2 seconds for FastAPI, and the next request about 0.14 to 0.25 seconds.

### Does it support async database drivers?

Yes. An `asyncpg` requirement is recognised as Postgres, like `psycopg`.

### Can I run background tasks?

Short tasks that a request starts can finish. But Antideploy runs one web process and an idle app sleeps, so a worker that waits for jobs will not stay alive. Use a [scheduled job](https://antideploy.com/blog/how-to-run-a-scheduled-job-on-your-app) to call a route on a schedule.

### Which Python version is used?

The one you pin in `.python-version`, `runtime.txt` or `pyproject.toml`. If you pin none, the builder chooses one.

## More guides, and the platform.

Each platform page covers one part of Antideploy: what it does, where it stops and the questions people ask. [See the whole platform](https://antideploy.com/platform), or [all the guides](https://antideploy.com/blog).

- [How to add a Postgres database to your app](https://antideploy.com/blog/how-to-add-a-postgres-database-to-your-app): Ask your agent. A Postgres 17 database is created beside your app and DATABASE_URL is set.
- [How to deploy a Flask app for free](https://antideploy.com/blog/how-to-deploy-a-flask-app-for-free): How your app is found, why to add gunicorn, the PORT variable and Postgres.
- [ERROR: Could not find a version that satisfies the requirement](https://antideploy.com/blog/could-not-find-a-version-that-satisfies-the-requirement): No version matches your requirements.txt, often because of the Python version. Pin Python or loosen the pin.

- [Hosting](https://antideploy.com/platform/hosting)
- [Database](https://antideploy.com/platform/database)
- [Environment variables](https://antideploy.com/platform/environment-variables)
- [Deployments](https://antideploy.com/platform/deployments)

Facts on this page were checked against the live platform on 7 October 2026.

## Deploy something. Start with one sentence.

Paste one sentence into your coding agent, click Approve once, and get a live link. No card, no trial clock.

To set this up, give your coding agent this sentence:

```text
Set this project up to deploy on Antideploy. Fetch https://antideploy.com/agent.md and follow it.
```
