Ingestion Layer
The Ingestion Layer is responsible for capturing Debezium change data events from various input streams (Kafka Connect, JSON files, etc.) and converting them into normalized Python models.
Module Summary
Abstract base that all ingestion handlers extend. |
|
JSON-mode ingestion. |
|
Connect-mode (JPype + io.debezium.embedded.Connect) ingestion handler. |
API Reference
Abstract base for all PyDebeziumAI ingestion handlers.
Each concrete handler wraps a pydbzengine engine (JSON or Connect mode) and dispatches normalized DebeziumEventModel instances to registered callbacks.
- class BaseIngestionHandler[source]
Bases:
ABCAbstract base that all ingestion handlers extend.
Subclasses implement engine construction; this base handles callback registration and dispatching so the sync pipeline stays decoupled.
Usage:
handler = JsonIngestionHandler() handler.add_event_callback(sync_manager.handle_event) handler.add_error_callback(my_error_logger) engine = handler.build_engine(debezium_props) engine.run()
- add_event_callback(cb)[source]
Register a callback that receives each normalized DebeziumEventModel.
- Parameters:
cb (Callable[[DebeziumEventModel], None])
- Return type:
None
JSON-mode ingestion handler.
Wraps pydbzengine’s BasePythonChangeHandler to consume CDC events serialized as JSON strings, parse them into canonical DebeziumEventModel instances, and dispatch to registered callbacks.
This mode works without a JVM bridge for record schema access — the Debezium engine serializes events to JSON before handing them to Python.
- class JsonIngestionHandler[source]
Bases:
BaseIngestionHandlerJSON-mode ingestion.
Usage:
handler = JsonIngestionHandler() handler.add_event_callback(sync_manager.handle_event) engine = handler.build_engine({ "name": "engine", "connector.class": "io.debezium.connector.postgresql.PostgresConnector", ... }) engine.run()
Connect-mode ingestion handler.
Uses JPype + io.debezium.embedded.Connect format to access Debezium
SourceRecord objects directly, avoiding the JSON serialization round-trip.
Wires the SourceRecordExtractor into the PyDebeziumAI pipeline:
- Java SourceRecord
- → SourceRecordExtractor (struct_to_dict, full type conversion)
- → DebeziumRecord
- → DebeziumEventModel
→ SyncManager callbacks
- class ConnectIngestionHandler(conversion_config=None, topic_class_map=None)[source]
Bases:
BaseIngestionHandlerConnect-mode (JPype + io.debezium.embedded.Connect) ingestion handler.
Matches the architecture from
debezium_connect.py+BaseConnectChangeHandler, integrated into the PyDebeziumAI pipeline.- Parameters:
conversion_config (ConversionConfig | None) – Controls type conversion (numeric_mode, tz_aware).
topic_class_map (Mapping[str, type[Any]] | None) – Maps topic names to Python classes for typed access.
Usage:
handler = ConnectIngestionHandler( conversion_config=ConversionConfig(numeric_mode="native"), ) handler.add_event_callback(sync_manager.handle_event) engine = handler.build_engine(debezium_props) engine.run()