Python
Built with uv, from pyproject.toml and uv.lock.
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 explainmoor deployHow it builds#
- Python version:
.python-version, or elserequires-python, or else the newest release;[python].versionoverrides them. A partial version (3.13) means its newest patch release. - Dependencies:
uv sync --locked --no-devwith auv.lock(a lock that does not matchpyproject.tomlfails the build),uv sync --no-devwithout one (with a warning), or for arequirements.txt, a virtual environment anduv pip install -r requirements.txt.[python].groupsand[python].extrasinstall more. - The virtual environment's
bincomes first onPATH, sopython,uvicornand the project's scripts are found withoutuv run.VIRTUAL_ENVis set, andPYTHONUNBUFFERED=1, so that output reaches the logs at once. - uv's cache is shared between 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:
- Use
ThreadingHTTPServer, notHTTPServer: the latter answers one connection at a time, and an idle connection from Moorage's proxy then holds up every other request. HTTPServerlooks up the name of the address it binds. On some machines that reverse lookup of 127.0.0.1 takes half a minute, and each new instance takes as long to start. Overrideserver_bind, as the sample intestdata/apps/pythondoes.
Production servers (uvicorn, gunicorn, hypercorn) have neither problem.
A complete app: the Tasks example, FastAPI with a web page, SQLite and migrations.