Skip to main content

Python Debezium Embedded Engine

Project description

License contributions welcome Create Pypi Release

pydbzengine

A Python module to use Debezium Engine in python. Consume Database CDC events using python.

Java integration is using Pyjnius, It is a Python library for accessing Java classes

Installation

Python+Java integration requires a Java Development Kit (JDK). Ensure a JDK is installed on environment.

install:

pip install pydbzengine
# install from github:
pip install https://github.com/memiiso/pydbzengine/archive/master.zip --upgrade --user

How to Use

First install the packages, pip install pydbzengine[dev]

from typing import List
from pydbzengine import ChangeEvent, BasePythonChangeHandler
from pydbzengine import Properties, 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 = Properties()
    props.setProperty("name", "engine")
    props.setProperty("snapshot.mode", "initial_only")
    # Add further Debezium connector configuration properties here.  For example:
    # props.setProperty("connector.class", "io.debezium.connector.mysql.MySqlConnector")
    # props.setProperty("database.hostname", "your_database_host")
    # props.setProperty("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()

How to consume events with dlt

For the full code please see dlt_consuming.py

https://github.com/memiiso/pydbzengine/blob/c4a88228aa66a2dc41b3dcc192615b1357326b66/pydbzengine/examples/dlt_consuming.py#L92-L153

Contributors

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydbzengine-3.1.1.0.tar.gz (46.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydbzengine-3.1.1.0-py3-none-any.whl (46.1 MB view details)

Uploaded Python 3

File details

Details for the file pydbzengine-3.1.1.0.tar.gz.

File metadata

  • Download URL: pydbzengine-3.1.1.0.tar.gz
  • Upload date:
  • Size: 46.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pydbzengine-3.1.1.0.tar.gz
Algorithm Hash digest
SHA256 6be5ee48525d20260219ba8c4294cd3e51153152fb7339389537c63750f285e2
MD5 3ef3824d83d6d211b54a81e46c233a75
BLAKE2b-256 93e3f1a8f41e1b49a46566fb09c1d86b379d779e9bf698b585e3d482ea8c4cb8

See more details on using hashes here.

File details

Details for the file pydbzengine-3.1.1.0-py3-none-any.whl.

File metadata

  • Download URL: pydbzengine-3.1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 46.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pydbzengine-3.1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6b058d82896498fbbb9cababae394f05df4d2afac6e24db6542952335bee3e26
MD5 64951a44bdec10849e88fb2b3e35ed2c
BLAKE2b-256 df4b5ba842f8946e8c2bf2fad78edf095e2f6fb86487a057824729c46233af0e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page