Events & Channels Extension¶
from sqlspec.extensions.events import (
AsyncEventBackendProtocol,
AsyncEventChannel,
AsyncEventListener,
AsyncTableEventQueue,
BaseEventQueueStore,
EventMessage,
EventRuntimeHints,
SyncEventBackendProtocol,
SyncEventChannel,
SyncEventListener,
SyncTableEventQueue,
build_queue_backend,
get_runtime_hints,
)
Database-native pub/sub (LISTEN/NOTIFY, Oracle Advanced Queuing) and durable table-backed event queues across all 20 adapters. See the Event Channels Guide for usage examples.
Event Channels & Listeners¶
SyncEventChannel
¶
AsyncEventChannel
¶
SyncEventListener
¶
Represents a running sync listener thread.
AsyncEventListener
¶
Represents a running async listener task.
EventMessage
¶
Structured payload delivered to event handlers.
Durable Table Queues & Stores¶
SyncTableEventQueue
¶
Bases: _BaseTableEventQueue
Sync table queue implementation.
AsyncTableEventQueue
¶
Bases: _BaseTableEventQueue
Async table queue implementation.
BaseEventQueueStore
¶
Bases: ABC, Generic[ConfigT]
Base class for adapter-specific event queue DDL generators.
This class provides a hook-based pattern for DDL generation. Adapters only
need to override _column_types() and optionally any hook methods for
dialect-specific variations:
_string_type(length): String type syntax (default: VARCHAR(N))_integer_type(): Integer type syntax (default: INTEGER)_timestamp_default(): Timestamp default expression (default: CURRENT_TIMESTAMP)_primary_key_syntax(): Inline PRIMARY KEY clause (default: empty, PK on column)_table_clause(): Additional table options (default: empty)
For complex dialects (Oracle PL/SQL, BigQuery CLUSTER BY), adapters may
override _table_ddl() directly.
build_queue_backend
¶
Build a table queue backend using adapter hints and extension overrides.
Runtime Hints, Protocols & Payload Helpers¶
EventRuntimeHints
¶
Adapter-specific defaults for event polling and leases.
get_runtime_hints
¶
Return runtime hints provided by the adapter configuration.
SyncEventBackendProtocol
¶
Bases: Protocol
Protocol for sync event backends.
All sync event backends (native or queue-based) must implement these methods.
AsyncEventBackendProtocol
¶
Bases: Protocol
Protocol for async event backends.
All async event backends (native or queue-based) must implement these methods.
encode_notify_payload
¶
Encode event data as JSON for NOTIFY payload.
Raises:
| Type | Description |
|---|---|
EventChannelError
|
If the encoded envelope exceeds the PostgreSQL notification budget. |
decode_notify_payload
¶
Decode JSON payload from NOTIFY into an EventMessage.