← Back to Blog
· Uppcoder Team

What is the cheapest way to host a FastAPI app with PostgreSQL?

FastAPIPostgreSQLPythonHostingUppcoder

Short answer: free, on Uppcoder’s free plan. It runs one FastAPI app with one PostgreSQL database on its own HTTPS address, with no card and no time limit. Ours was running in 39 seconds, with the database driver installed and the connection string waiting in the environment. When you outgrow it, paid plans start at €5 a month.

What you get for free

  • One app with one database: 2 GB of memory and 2 GB of disk
  • No card, and no time limit; if the free plan is ever changed or ended, everyone on it hears from us by email at least 60 days before
  • Its own HTTPS address, with FastAPI’s interactive API page at /docs
  • VS Code in the browser and a terminal next to the app, or SSH from your own editor
  • Backed up every night to a separate server: a copy from each of the last seven days and one from each of the last four weeks
  • A public status page for the servers apps run on

The database is already wired in

The app gets the whole connection as DATABASE_URL, and the parts as POSTGRES_HOST, POSTGRES_PORT, POSTGRES_DB, POSTGRES_USER and POSTGRES_PASSWORD, so no password sits in your code. The PostgreSQL driver (psycopg) is installed when the app starts. Reading from PostgreSQL is a few lines (the guide has the full example, which we ran on a fresh app):

import os
import psycopg
from fastapi import FastAPI

app = FastAPI()

@app.get("/notes")
def notes():  # reads the notes table the guide's example creates
    with psycopg.connect(os.environ["DATABASE_URL"]) as conn:
        return conn.execute("select id, text from notes order by id").fetchall()

How it works

  1. Sign up at portal.uppcoder.com and confirm your email; then Billing, Spark, Start free.
  2. Create a stack: pick FastAPI, add PostgreSQL and give it a username and password. It is connected to the app automatically.
  3. Deploy. The starter answers on its own address, and /docs shows the API.
  4. Open main.py in VS Code and write your API; it runs on the same address.

The full walk-through, including a small notes API that creates its own table, is in the guide: Deploy a FastAPI app with PostgreSQL, free. To start from a repository, use the fastapi-postgresql-starter on GitHub and paste its address on the FastAPI card.

Questions people ask

Why not just a cheap VPS? A VPS is cheap until you count the time: installing PostgreSQL, a reverse proxy, certificates, updates and backups. Here those are done, and the free plan costs nothing at all.

Can I use my own domain? Your own domain comes with every paid plan, from €5 a month. On the free plan the app has its own HTTPS address.

Where does it run? On our own infrastructure, which can be kept to the region you choose, such as Europe or the United States.

Is it an alternative to Render, Railway or Heroku? For a small FastAPI app with a database, yes: the app, its database and an editor in one place, on a free plan that does not run out.

Related: Where can I deploy a Django app with PostgreSQL for free? · Uppcoder: build, run and teach software in the cloud