Skip to content

pyramid-sa

Pyramid SQLAlchemy Integration — a reusable library that wires SQLAlchemy into any Pyramid application via config.include("pyramid_sa").

Features

  • Session management — engine creation, transaction-managed sessions via pyramid_tm + zope.sqlalchemy, request.dbsession as a reified property
  • Declarative baseBase with consistent naming conventions and utility methods (as_dict, copy_with) on every model
  • Audit trail — opt-in AuditMixin that tracks created_at, updated_at, created_by, updated_by, created_ip, updated_ip
  • Soft delete — opt-in SoftDeleteMixin with automatic query filtering, delete interception, partial unique indexes, and safe restore
  • Error mapping — exception tween that translates NoResultFound to 404 and IntegrityError to 409, with customizable error bodies
  • JSON rendering — adapters for datetime, date, and UUID out of the box
  • Alembic scaffolddb init-alembic command copies pre-wired templates into your project
  • CLI commandsdb drop and db initialize for schema management
  • Test fixtures — companion pyramid-sa-testing package with a pytest plugin for PostgreSQL-backed test sessions

Quick install

pip install pyramid-sa

For test fixtures (dev only):

pip install pyramid-sa-testing

Where to go next