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 "bubus[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 bubus_events)
  • name: optional bridge label
from bubus import PostgresEventBridge

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

Setup with a bus

from bubus import EventBus, PostgresEventBridge

bus = EventBus('AppBus')
bridge = PostgresEventBridge('postgresql://user:pass@localhost:5432/mydb/bubus_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.
  • Event field columns are created on demand to track evolving payload schemas.
  • Runtime requirements: Python needs asyncpg, TypeScript needs pg and Node.js.