Open-source SQLAlchemy tooling

Tooling that feels native to SQLAlchemy.

Django developers get assertNumQueries, nplusone, and the Debug Toolbar. SQLAlchemy developers get told to write their own event listener. These are the missing pieces — small, sharply scoped, and held to a hard quality bar.

Packages

queryspy

N+1 and query-budget detection for SQLAlchemy 2.0 — sync and async.

N+1 detected: 11 queries for User.addresses (lazy load)
  triggered from app/services/users.py:28 in list_users()
  SELECT address.id AS address_id, address.email AS address_email, ...
  fix: .options(selectinload(User.addresses))

Point it at the test suite you already have. pytest --queryspy-strict fails any test that triggers an N+1 and names the line of your code responsible, with a fix you can paste. Async included — attribution walks the greenlet chain SQLAlchemy runs lazy loads inside.

More is planned. Nothing is announced until it ships.

Principles

Public API only
No monkeypatching of SQLAlchemy internals. That is precisely why the previous generation of these tools stopped working instead of being ported.
A false positive is worse than a missed detection
A tool that flags correct code gets uninstalled the same day. False-positive suites are release gates here, weighted equally with detection.
Measure, don't assume
Behaviour claims in these repos are backed by scripts that were actually run against a real session. Two of queryspy's design decisions reversed once measured.
Minimal dependencies
Every package declares the smallest runtime closure it can defend, and the release gate audits that closure rather than the development tree.