The most widely used Python SQL toolkit and ORM. v2.0 released January 2023 — massive breaking change from v1.x. The entire ORM query API shifted from session.query() to select(). engine.execute() removed. Passing raw strings to execute() removed. Typed mapped_column() replaces Column(). Current version: 2.0.48 (Mar 2026). Flask-SQLAlchemy's Model.query pattern is also legacy in v2.
pip install sqlalchemyVerified import paths — ran on the pinned version, not inferred.
SQLAlchemy 2.0 ORM quickstart with typed models.
Use 'with engine.connect() as conn: conn.execute(text(...))'
from sqlalchemy import text; conn.execute(text('SELECT 1'))from sqlalchemy.orm import DeclarativeBase; class Base(DeclarativeBase): pass
Replace session.query(Model).filter(...) with session.scalars(select(Model).where(...))
users = session.scalars(select(User)).all() — not session.execute(select(User)).all()
Use 'with engine.begin() as conn:' for autocommit. Or call session.commit() explicitly.
id: Mapped[int] = mapped_column(primary_key=True)