Deploy a FastAPI app to Miget using the auto-detecting Python buildpack, a Procfile to define your start command, and a git push to the Miget builder.

Prerequisites

  • A Miget account
  • Git installed locally
  • A FastAPI project with a requirements.txt that includes fastapi and uvicorn
Every app on Miget must listen on 0.0.0.0:5000. Miget sets an immutable PORT=5000, and public ingress only reaches port 5000. See Ports for details.

Prepare your app

The buildpack auto-detects Python from your requirements.txt. Unlike Django, FastAPI is not auto-served, so you must define the start command yourself with a Procfile. Create a Procfile in your project root:
Procfile
web: uvicorn main:app --host 0.0.0.0 --port 5000
Adjust main:app to match your module:app (for example, if your app instance lives in app/server.py as app, use app.server:app).
For more concurrency, run multiple workers with Gunicorn and the Uvicorn worker class:
Procfile
web: gunicorn -k uvicorn.workers.UvicornWorker main:app --bind 0.0.0.0:5000
Add gunicorn to your requirements.txt when you use this option.
Make sure your requirements.txt includes the essentials:
requirements.txt
fastapi
uvicorn

Deploy with git push

1

Create the application

Go to app.miget.com, click New → Application, give your app a name, choose a resource, and click Next.
2

Choose the buildpack

Select Auto detection (Miget Buildpacks), pick a size, and click Next.
3

Pick the git push method

Choose git push, click Create, and copy the deploy token shown.
4

Add the remote and push

Add the Miget remote and push your code:
git remote add miget https://git.<region>.miget.io/<your-miget-name>/<app-name>
git push miget
Replace <region>, <your-miget-name>, and <app-name> with the values from your app. See Git push to builder for the full flow.
Once the build finishes, your FastAPI app is live and serving on port 5000.
This guide uses git push, but it’s one of several ways to deploy. You can also connect a GitHub repository for auto-deploys and pull request previews, deploy from a public Git repository, or push a prebuilt container image. See all deployment methods.

Connect a database

To add persistence, attach a PostgreSQL addon to your app. Miget provisions the database and auto-injects a DATABASE_URL (a postgres://... connection string) into your app’s environment. Read it from the environment in your code, for example with SQLAlchemy or asyncpg:
main.py
import os

DATABASE_URL = os.environ["DATABASE_URL"]
For an async driver, you may need to adapt the URL scheme - for example, rewrite postgres:// to postgresql+asyncpg:// before passing it to your async engine.
See PostgreSQL to provision the addon and Using secrets to manage other environment variables.

Next steps

Custom domains

Point your own domain at your FastAPI app.

Ports

Learn how ingress and the immutable port 5000 work.

PostgreSQL

Provision and connect a managed Postgres database.

Fair Scheduler

Understand how Miget shares compute across your apps.