Python

Built with uv, from pyproject.toml and uv.lock.

On this page

Moorage builds Python apps with uv: it installs the Python version the project asks for and the project's dependencies into a virtual environment, in the directory the app runs from.

The app#

A FastAPI app, for example, with its dependencies in pyproject.toml and locked in uv.lock (uv lock):

[project]
name = "hello"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["fastapi", "uvicorn"]
# main.py
from fastapi import FastAPI

app = FastAPI()


@app.get("/healthz")
def health():
    return "ok"


@app.get("/")
def hello():
    return {"hello": "from Python"}

Moorage finds the app object — in main.py, app.py, server.py, asgi.py, wsgi.py or api.py, or in those files of a package at the top (a directory with an __init__.py) — and runs uvicorn main:app --host 127.0.0.1 --port $PORT. A Django or Flask app with gunicorn among its dependencies is found the same way, and a project with a single [project.scripts] entry runs that script. Otherwise, say what to run in moorage.toml:

[app]
name = "hello"

[processes.web]
command = "uvicorn main:app --host 127.0.0.1 --port $PORT --proxy-headers"
health = { path = "/healthz" }

[release]
command = "alembic upgrade head"

Deploy#

moor manifest explain
moor deploy

How it builds#

The release command#

[release].command runs once per deployment, after the build and before the new release takes traffic, with the release's variables: database migrations go there. If it fails, the deployment fails and the previous release keeps serving. It does not run on a rollback or a change of variables. [release].on_create runs once, after an environment's first release (to seed data).

Two traps of http.server#

Apps built on the standard library's http.server:

Production servers (uvicorn, gunicorn, hypercorn) have neither problem.

A complete app: the Tasks example, FastAPI with a web page, SQLite and migrations.

Suggest a change to this page