SQLAlchemy Cheatsheet 11 — Events and Hooks
Cheatsheet: engine events (connect/checkout/before_cursor_execute), session events (before_commit), mapper hooks (before_insert/update/delete), attribute events.
Cheatsheet: engine events (connect/checkout/before_cursor_execute), session events (before_commit), mapper hooks (before_insert/update/delete), attribute events.
Testing SQLAlchemy: real DBs via testcontainers, per-test transactions, factory_boy, async fixtures, and CI patterns.
Cheatsheet: collections, json, os, sys, subprocess, secrets, hashlib, hmac.
Cheatsheet: ValidationError.errors(), loc / type / msg, custom error envelopes, FastAPI 400/422.
Cheatsheet: repository classes, unit-of-work, generic base repo, service-layer separation.
Production SQLAlchemy: pool sizing with PgBouncer, read replica routing, OTEL instrumentation, multi-tenancy with RLS, and graceful failure modes.
Cheatsheet: httpx Client / AsyncClient, requests, timeouts, retries, streaming.
Cheatsheet: from_attributes=True, computed fields from ORM, eager-loading relations, exclude sensitive.
Cheatsheet: SoftDeleteMixin, auto-timestamps via events, audit log table, with_loader_criteria for transparent filtering.
Cheatsheet: Typer for modern CLIs, Click for power users, argparse for stdlib.