Talk to a database (ORMs)
Must knowMust know
An ORM maps tables to Python classes, so you query and save objects instead of writing SQL strings. All three options below do that; they differ in how much they do for you and whether they are built for async code.
- SQLAlchemy is the standard. Its core gives you a SQL toolkit and its ORM a full unit of work, with sync and async sessions. Learn it first: most other tools build on it or copy its ideas.
- SQLModel sits on top of SQLAlchemy and Pydantic: one class is both your table and your API schema. A good fit with FastAPI when the models are simple.
- Tortoise ORM is async from the ground up, with a Django-like API. Pick it for an async service when you prefer that style over SQLAlchemy’s.
Whatever you choose, keep learning SQL itself: an ORM saves typing, not understanding what the database does.