sqlalchemy
Installation
SKILL.md
SQLAlchemy
Overview
SQLAlchemy is the standard Python ORM and SQL toolkit. The 2.x API is type-friendly and has first-class asyncio support: define models as Python classes with Mapped[...] annotations, write queries with select(), and manage schema changes with Alembic migrations.
The current release line is 2.1 (2.1.1, September 2026); 2.0.x (last seen: 2.0.54) is the line for Python older than 3.11. What 2.1 changes for existing 2.0 code:
- Python 3.11 is the minimum.
greenletis no longer installed by default. Async code needspip install "sqlalchemy[asyncio]", otherwise importingsqlalchemy.ext.asyncioraisesImportError.- A URL without a driver,
postgresql://..., now selects psycopg 3 instead of psycopg2. Writepostgresql+psycopg2://to keep the old driver. Oracle likewise defaults to python-oracledb. select(a, b)is typedSelect[int, str]instead ofSelect[Tuple[int, str]](needs mypy 1.7+).- The session autoflushes before every statement, including
text()and Core statements.