Python reference

SQLAlchemy
cheat sheet.

SQLAlchemy ORM and Core queries, relationships, transactions, async sessions, and FastAPI integration, with Python and SQL examples.

27 topics114 code examplesUpdated
How SQLAlchemy fits together
01Model describesClasses and tables define data.
02Statement buildsPython expressions become SQL.
03Session runsOne transaction tracks changes.
04Database commitsRows are stored or rolled back.
Jump to a specific topic

Choose a chapter

4 chapters · 27 topics

CHAPTER 01 / 04

Models, sessions, and queries

Configure engines, map models, manage sessions, query records, and load relationships.

9 topics
CHAPTER 02 / 04

Advanced queries and async sessions

Use advanced queries, schema tools, custom types, reflection, asynchronous sessions, and FastAPI integration.

8 topics
CHAPTER 03 / 04

Mappings, connections, and dialects

Extend mappings and inheritance, use Core connections, and work with dialects and events.

6 topics