Skip to main content
PostgresEventBridge stores event payloads in a Postgres table and uses LISTEN/NOTIFY for low-latency fanout.

Optional dependencies

Install the Postgres extra (recommended):
pip install "abxbus[postgres]"
Equivalent direct dependency install:
pip install asyncpg

Constructor params

  • table_url: postgresql://user:pass@host:5432/dbname[/tablename]?...
  • channel: optional notify/listen channel (defaults to abxbus_events)
  • name: optional bridge label
from abxbus import PostgresEventBridge

bridge = PostgresEventBridge(
    'postgresql://user:pass@localhost:5432/mydb/abxbus_events',
    channel='abxbus_events',
    name='PgBridge',
)

Setup with a bus

from abxbus import EventBus, PostgresEventBridge

bus = EventBus('AppBus')
bridge = PostgresEventBridge('postgresql://user:pass@localhost:5432/mydb/abxbus_events')

bus.on('*', bridge.emit)
bridge.on('*', bus.emit)

Behavior

  • emit(...) upserts event payload data into the bridge table, then sends NOTIFY with the event id.
  • on(...) registers inbound handlers and auto-starts listener startup.
  • On notifications, the bridge fetches the full row payload, reconstructs an event, resets it, and emits locally.
  • Columns are created on demand only for event_* fields.
  • The full event JSON is stored in event_payload (not just non-event_* fields).
  • event_* columns are also stored as flat mirrored fields for indexing/querying.
  • Rehydration merges event_payload with event_* column values back into a flat event object.
  • Runtime requirements: Python needs asyncpg, TypeScript needs pg and Node.js.