Registry / database / sqlalchemy

sqlalchemy

JSON →
library2.0.48pypypi✓ verified 33d ago

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.

databaseweb-framework
Install & Compatibility
Where this runs
tested against v2.0.50 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.950 runs
installs and imports cleanly · install 0.0s · import 0.684s · 42.5MB
glibc
py 3.103.950 runs
installs and imports cleanly · install 3.2s · import 0.616s · 41MB
41MB installed
● package 41MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

from sqlalchemy import select
from sqlalchemy.orm import Session

SQLAlchemy 2.0 ORM quickstart with typed models.

# pip install sqlalchemy from sqlalchemy import create_engine, String, select, text from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, Session class Base(DeclarativeBase): pass class User(Base): __tablename__ = 'users' id: Mapped[int] = mapped_column(primary_key=True) name: Mapped[str] = mapped_column(String(50)) engine = create_engine('sqlite:///test.db') Base.metadata.create_all(engine) with Session(engine) as session: # Insert session.add(User(name='Alice')) session.commit() # Query — v2 style stmt = select(User).where(User.name == 'Alice') user = session.scalars(stmt).first() print(user.name) # 'Alice'
Debug
Known footguns
breakingengine.execute() removed in v2.0. Raises AttributeError. Most LLM-generated SQLAlchemy code uses engine.execute().
breakingPassing raw strings to execute() removed. conn.execute('SELECT 1') raises ArgumentError in v2.
breakingdeclarative_base() from sqlalchemy.ext.declarative is legacy in v2. Still works but generates RemovedIn20Warning.
gotchasession.query() is legacy in v2 — still works but not recommended. Flask-SQLAlchemy's Model.query is also legacy. LLMs trained pre-2023 generate session.query() patterns.
gotchasession.execute() now returns a Result object. For ORM models use session.scalars() to get model instances directly, not session.execute().
gotchaAutocommit behavior changed in v2. Connections no longer autocommit. Must explicitly use with engine.begin() for autocommit or session.commit().
gotchaColumn() without type annotations still works but loses IDE/mypy type inference. mapped_column() with Mapped[] is the v2 typed approach.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
68 hits · last 30 days
petalbot
9
bytedance
9
gptbot
4
ahrefsbot
4
amazonbot
3
claudebot
3
dotbot
2
sogoubot
1
oai-searchbot
1
Resources