Getting StartedΒΆ
Install the package (see Installation)
Enable the SQLAlchemy and/or Alembic event listeners and components. It is critical that this happens prior to adding any tables you want to audit to the metadata object.
from sqlalchemy import MetaData import sqlalchemy_postgresql_audit sqlalchemy_postgresql_audit.enable() metadata = MetaData()
Add an audit.options key to the table info attribute.
ORM Style
class Base: @declared_attr def __table_args__(self): return { 'info': { 'audit.options': { 'enabled': True, }, } }
Core Style
table = Table( "bar", metadata, Column("foo", String), info={ "audit.options": { "enabled": True } }, )
Install the triggers and functions from the metadata
from sqlalchemy_postgresql_audit install_audit_triggers install_audit_triggers(metadata, engine)