Tutorial - User Guide¶
The tutorial follows the chapters of FastAPI's own tutorial. Each page takes one FastAPI feature and says what py2axum does with it, so you can read it next to the FastAPI page you already know. Every page has the same layout:
- a short introduction naming the feature it covers;
- an example application using it, which py2axum translates and whose binary answers like FastAPI;
- What is native: what the binary reproduces, and how precisely;
- What stays in Python: what is refused at compile time (with
file:line), and can be left to a Python process with--python-side(Hybrid mode); - Differences: where the binary is knowingly not identical to the Python application, when there are any.
py2axum refuses rather than guesses: a construct is either translated with the behaviour described in these pages or not translated at all. The full list of pages that make up the supported subset is in Supported subset.
| Page | FastAPI feature |
|---|---|
| Parameters | path, query and header parameters |
| Request body | JSON bodies |
| Models (Pydantic) | Pydantic v2 models, validators, settings |
| Responses | response_model, response classes, streaming |
| Handling errors | HTTPException, exception handlers |
| Dependencies | Depends, yield dependencies, the session dependency |
| Security | OAuth2, HTTP Bearer and Basic |
| Middleware | Starlette's middleware stack, raw ASGI middleware |
| CORS | CORSMiddleware |
| SQL databases | SQLAlchemy 2.0, async and sync |
| Forms and files | Form(), File(), UploadFile |
| Background tasks | BackgroundTasks |
| WebSockets | @app.websocket |
| Lifespan events | FastAPI(lifespan=...) |
| Bigger applications | routers, factories, routing, mounts |
| Testing | your tests, and testing the binary |