---
title: "Deploy a FastAPI App"
description: "Deploy a FastAPI application to Miget with git push, a Procfile, and an optional PostgreSQL database."
---
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](https://app.miget.com)
- 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](/networking/ports) for details.
## Prepare your app
The buildpack [auto-detects Python](/overview/buildpacks) 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 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 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:
```text requirements.txt
fastapi
uvicorn
```
## Deploy with git push
Go to [app.miget.com](https://app.miget.com), click **New → Application**, give your app a name, choose a resource, and click **Next**.
Select **Auto detection (Miget Buildpacks)**, pick a size, and click **Next**.
Choose **git push**, click **Create**, and copy the deploy token shown.
Add the Miget remote and push your code:
```bash
git remote add miget https://git..miget.io//
git push miget
```
Replace ``, ``, and `` with the values from your app. See [Git push to builder](/deployments/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](/deployments/github-integration) for auto-deploys and pull request previews, deploy from a public Git repository, or push a prebuilt [container image](/deployments/container-registry). See [all deployment methods](/deployments/how-it-works).
## 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:
```python 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](/databases/postgresql) to provision the addon and [Using secrets](/deployments/using-secrets) to manage other environment variables.
## Next steps
Point your own domain at your FastAPI app.
Learn how ingress and the immutable port 5000 work.
Provision and connect a managed Postgres database.
Understand how Miget shares compute across your apps.