pydbzengine
A Pythonic interface for the Debezium Engine, allowing you to consume database Change Data Capture (CDC) events directly in your Python applications.
Full Documentation: https://memiiso.github.io/pydbzengine
Features
- Pure Python Interface: Interact with the powerful Debezium Engine using simple Python classes and methods.
- Pluggable Event Handlers: Easily create custom handlers to process CDC events according to your specific needs.
- Built-in Iceberg Handler: Stream change events directly into Apache Iceberg tables with zero boilerplate.
- Seamless Integration: Designed to work with popular Python data tools like dlt (data load tool).
- Apache Airflow Operator: Run Debezium engines directly within Airflow DAGs using the built-in DebeziumEngineOperator.
- Asynchronous & Snapshot Helpers: Run engines with time limits or terminate them automatically once initial snapshots complete using Utils.
- All Debezium Connectors: Supports all standard Debezium connectors (PostgreSQL, MySQL, SQL Server, Oracle, etc.).
How it Works
This library acts as a bridge between the Python world and the Java-based Debezium Engine. It uses JPype to manage the JVM and interact with Debezium's Java classes, exposing a clean, Pythonic API so you can focus on your data logic without writing Java code.
Pre-available Data Handling Classes
pydbzengine comes with several built-in handlers. For detailed configuration and advanced usage, see the Handlers Documentation.
Apache Iceberg Handler
Stream CDC events directly into Apache Iceberg tables.
IcebergChangeHandlerV2(Recommended): Automatically infers schemas and manages table structures with native data types.IcebergChangeHandler: Appends raw change data (JSON) to source-equivalent tables using a fixed schema.
dlt (data load tool) Handler
DltChangeHandler: Integrates with thedltlibrary to load data into any supported destination (DuckDB, BigQuery, Snowflake, etc.).
Custom Handlers
BasePythonChangeHandler: Extend this class to implement your own custom processing logic in pure Python.
Installation
Prerequisites
You must have a Java Development Kit (JDK) version 17 or newer installed and available in your system's PATH.
Recommended Installation: From GitHub
[!WARNING] Due to the package size (including
.jarartifacts), new versions are no longer published to PyPI. The package on PyPI is outdated. It is highly recommended to install the package directly from GitHub to get the latest features and fixes.
You can install either the latest development version from the main branch or a specific, stable version from a release tag.
To install the latest development version:
# For core functionality
pip install "git+https://github.com/memiiso/pydbzengine.git"
# With extras (e.g., iceberg, dlt)
pip install "pydbzengine[iceberg] @ git+https://github.com/memiiso/pydbzengine.git"
pip install "pydbzengine[dlt] @ git+https://github.com/memiiso/pydbzengine.git"
pip install "pydbzengine[dev] @ git+https://github.com/memiiso/pydbzengine.git"
# To install a specific version from a release tag (e.g., 3.4.1.0):
pip install "pydbzengine @ git+https://github.com/memiiso/pydbzengine.git@3.4.1.0"
Alternative: From PyPI (Outdated Version)
An older version is available on PyPI. You can install it, but be aware that it lacks recent features and updates.
# For core functionality
pip install pydbzengine
# With extras
pip install "pydbzengine[iceberg]"
pip install "pydbzengine[dlt]"
How to Use
Consume events With custom Python consumer
- First install the packages:
pip install "pydbzengine[dev] @ git+https://github.com/memiiso/pydbzengine.git" - Second, extend the BasePythonChangeHandler and implement your Python consuming logic. See the example below:
from typing import List
from pydbzengine import ChangeEvent, BasePythonChangeHandler
from pydbzengine import DebeziumJsonEngine
class PrintChangeHandler(BasePythonChangeHandler):
"""
A custom change event handler class.
This class processes batches of Debezium change events received from the engine.
The `handleJsonBatch` method is where you implement your logic for consuming
and processing these events. Currently, it prints basic information about
each event to the console.
"""
def handleJsonBatch(self, records: List[ChangeEvent]):
"""
Handles a batch of Debezium change events.
This method is called by the Debezium engine with a list of ChangeEvent objects.
Change this method to implement your desired processing logic. For example,
you might parse the event data, transform it, and load it into a database or
other destination.
Args:
records: A list of ChangeEvent objects representing the changes captured by Debezium.
"""
print(f"Received {len(records)} records")
for record in records:
print(f"destination: {record.destination()}")
print(f"key: {record.key()}")
print(f"value: {record.value()}")
print("--------------------------------------")
if __name__ == '__main__':
props = {
"name": "engine",
"snapshot.mode": "initial_only",
# Add further Debezium connector configuration properties here. For example:
# "connector.class": "io.debezium.connector.mysql.MySqlConnector",
# "database.hostname": "your_database_host",
# "database.port": "3306",
}
# Create a DebeziumJsonEngine instance, passing the configuration properties and the custom change event handler.
engine = DebeziumJsonEngine(properties=props, handler=PrintChangeHandler())
# Start the Debezium engine to begin consuming and processing change events.
engine.run()
Consume events to Apache Iceberg
from pyiceberg.catalog import load_catalog
from pydbzengine import DebeziumJsonEngine
from pydbzengine.handlers.iceberg import IcebergChangeHandlerV2
conf = {
"uri": "http://localhost:8181",
# "s3.path-style.access": "true",
"warehouse": "warehouse",
"s3.endpoint": "http://localhost:9000",
"s3.access-key-id": "minioadmin",
"s3.secret-access-key": "minioadmin",
}
catalog = load_catalog(name="rest", **conf)
handler = IcebergChangeHandlerV2(catalog=catalog, destination_namespace=("iceberg", "debezium_cdc_data",))
dbz_props = {
"name": "engine",
"snapshot.mode": "always",
# ....
# Add further Debezium connector configuration properties here. For example:
# "connector.class": "io.debezium.connector.mysql.MySqlConnector",
}
engine = DebeziumJsonEngine(properties=dbz_props, handler=handler)
engine.run()
Consume events with dlt
For the full code please see dlt_consuming.py
from pydbzengine import DebeziumJsonEngine
from pydbzengine.helper import Utils
from pydbzengine.handlers.dlt import DltChangeHandler
import dlt
# Create a dlt pipeline and set destination. in this case DuckDb.
dlt_pipeline = dlt.pipeline(
pipeline_name="dbz_cdc_events_example",
destination="duckdb",
dataset_name="dbz_data"
)
handler = DltChangeHandler(dlt_pipeline=dlt_pipeline)
dbz_props = {
"name": "engine",
"snapshot.mode": "always",
# ....
}
engine = DebeziumJsonEngine(properties=dbz_props, handler=handler)
# Run the Debezium engine asynchronously with a timeout.
# This runs for a limited time and then terminates automatically.
Utils.run_engine_async(engine=engine, timeout_sec=60)
Contributors
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydbzengine-3.6.0.0.tar.gz.
File metadata
- Download URL: pydbzengine-3.6.0.0.tar.gz
- Upload date:
- Size: 200.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02f2c94ef6e9b07aabbb89e0fb171ed245df79ac3cae2bb038966e40ae11f516
|
|
| MD5 |
537e9b9a40c99170bbe3e993edc763ca
|
|
| BLAKE2b-256 |
5c83cb86d8644077e82b4331b83e7b25eef6936e2de928f1155c3b08d9b3dac0
|
Provenance
The following attestation bundles were made for pydbzengine-3.6.0.0.tar.gz:
Publisher:
release.yml on memiiso/pydbzengine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydbzengine-3.6.0.0.tar.gz -
Subject digest:
02f2c94ef6e9b07aabbb89e0fb171ed245df79ac3cae2bb038966e40ae11f516 - Sigstore transparency entry: 2172894623
- Sigstore integration time:
-
Permalink:
memiiso/pydbzengine@387fee20a0ec983b72c1f3b73aadf1676527c16f -
Branch / Tag:
refs/tags/3.6.0.0 - Owner: https://github.com/memiiso
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@387fee20a0ec983b72c1f3b73aadf1676527c16f -
Trigger Event:
push
-
Statement type:
File details
Details for the file pydbzengine-3.6.0.0-py3-none-any.whl.
File metadata
- Download URL: pydbzengine-3.6.0.0-py3-none-any.whl
- Upload date:
- Size: 200.8 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d10530ed37ac8067562b0f6a0fec5c6687eebd1bddba5969088324a7241feb9d
|
|
| MD5 |
221ce3d38f6d8ba1727c48e874a618cf
|
|
| BLAKE2b-256 |
221346a607efdd2d381583bc2ab133c7df969a21437c44a69b5d8e9d7a1f7617
|
Provenance
The following attestation bundles were made for pydbzengine-3.6.0.0-py3-none-any.whl:
Publisher:
release.yml on memiiso/pydbzengine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydbzengine-3.6.0.0-py3-none-any.whl -
Subject digest:
d10530ed37ac8067562b0f6a0fec5c6687eebd1bddba5969088324a7241feb9d - Sigstore transparency entry: 2172894700
- Sigstore integration time:
-
Permalink:
memiiso/pydbzengine@387fee20a0ec983b72c1f3b73aadf1676527c16f -
Branch / Tag:
refs/tags/3.6.0.0 - Owner: https://github.com/memiiso
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@387fee20a0ec983b72c1f3b73aadf1676527c16f -
Trigger Event:
push
-
Statement type: