Building a FastAPI or Flask app in Coolify with UV

Search for a command to run...

No comments yet. Be the first to comment.
Notion isn't exactly known as a speed demon... On Android it can take 30+ seconds to share a URL to the Notion app. It's faster to paste the link in the Notion app directly. I know because I do it 10-

When dad’s phone died I was the first one mom called for help. She always apologizes when calling for help. I’m not sure if she’s just being polite or she really doesn’t know the joy it brings me to b

Last year, I learned QGIS through the GIS and Spatial Analysis for Urban Practitioners course by All Things Urban. This year, with free Udemy access via SFPL, I'm looking to expand my skills. First, I dug up my old final project to revisit and share....

TLDR: I made a tool to do this: Wikidata string to QID tool (source). Bulk adding information to Wikidata by hand is a pain. I have an idea for creating a map of MVNOs (mobile virtual network operators) and their ownership (AT&T owns Cricket, Verizon...

Friends often joke about how bad FixBus is but none of the ~10 rides I've been on were particularly unpleasant. In fact, this most recent bus even had 250 MB of free WiFi. I didn’t bother using it but I found it to be an amusingly small amount for a ...

So, you want to start a new Python app for Coolify with the latest and greatest tools? Here’s how to do it.
At the end of the day, the process is relatively simple. However, despite having worked with all of these tools on existing projects, I hadn’t really set up new projects with them and didn’t find a complete guide so here goes.
uv - the replacement for pip that has been skyrocketing in popularity. It takes away a lot of the pain points.fastapi or flask - two popular web frameworks for Python. Flask is very barebones and time tested. fastapi is more full featured with batteries included.coolify - a very simple and easy tool for self hosting apps. Similar to Heroku or Vercel. (This tutorial assumes you already have coolify setup)nixpacks - this automatically generates docker images for you based on your repo’s structure. GitHub - hosted version control. Mentioning this here because we’ll have a push-to-deploy setup.Initialize your uv project:
This command sets up your Python project structure, creating essential files like pyproject.toml to manage dependencies.
uv init hello-world && cd hello-world
Add your web framework dependency:
Use uv add to install either fastapi (with optional extras like standard for uvicorn and pydantic) or the classic flask.
# For FastAPI
uv add "fastapi[standard]"
# Or for Flask
uv add flask
Create your application code:
Add starter code to main.py. Here's the example from the FastAPI documentation:
# main.py
from typing import Union
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
return {"item_id": item_id, "q": q}
Configure the start command for Nixpacks:
Create a nixpacks.toml file. This tells Nixpacks (and therefore Coolify) how to run your application inside the container.
touch nixpacks.toml
Add the following content. We use port 3000 as it's the default Coolify expects.
For FastAPI (using uvicorn):
# nixpacks.toml
[start]
cmd = "fastapi run main.py --port 3000"
For Flask (using gunicorn):
# nixpacks.toml
[start]
cmd = "gunicorn -w 4 -b 0.0.0.0:3000 main:app"
Commit your code:
git add .
git commit -m "Initial project setup"
# Push to your GitHub repository
git push origin main
Configure the application in Coolify:
Nixpacks as the build pack and 3000 as the port based on your nixpacks.toml.Deploy:
If you’re not using GitHub you can also configure webhooks in Coolify.
You probably want to add a .gitignore file for the __pycache__ directory
This is written for Coolify v4. Since v5 was just announced by the time you read this things on the Coolify side may have changed.
The source code for the Flask version is available here.
Thanks for reading!