Getting started¶
This guide takes you from pip install py2axum to a binary serving a FastAPI application, using the example in
examples/bookshelf: a reading-list
API with users, JWT authentication, books, reviews and a WebSocket. Then it shows how to do the same with your
own application.
- Installation: install py2axum and get the examples.
- First application: generate and build the crate, run the binary, compare it with FastAPI, then do the same with your own application.
py2axum check: what translates, route by route, and what to do when something is refused.- Hybrid mode: the routes left to a Python process next to the binary.
- Watch mode: regenerate, rebuild and restart the binary on each change while you port.
- Migrating an existing application: from uvicorn in production to the binary, step by step, with a switch you can undo.
Deploying the binary (Docker, Kubernetes) is covered in Deployment, its settings in Environment variables.
What you need¶
- Python ≥ 3.12, at least as recent as the one your application targets: the transpiler parses your code
with its own
astmodule, which only knows its own syntax. - Rust (stable, via rustup) to compile the generated crate. The first release build takes a few minutes; later builds only recompile your code.
- PostgreSQL: the runtime's database layer targets PostgreSQL (through sqlx).
- An application built on FastAPI, Pydantic v2 and SQLAlchemy 2.0 (async or sync sessions), within the tested version ranges.