Skip to main content

MySQL 8.4+ / MariaDB 10.11+ CDC engine - Python binding (native ctypes)

Project description

mysql-event-stream — Python Binding

CI PyPI License Python MySQL MariaDB Platform

A lightweight CDC (Change Data Capture) engine for Python supporting MySQL 8.4+ and MariaDB 10.11+. Parses binlog replication streams and emits structured row-level change events (INSERT / UPDATE / DELETE).

Built on a self-contained C++ core using ctypes FFI for high throughput and low latency. No external MySQL client library (libmysqlclient) required.

Install

pip install mysql-event-stream

Platform wheels are available for:

  • Linux x86_64 and aarch64 (recommended for server deployments)
  • macOS 15.0 or newer on x86_64 and arm64 (development use)

Usage

Parsing binlog bytes

from mysql_event_stream import CdcEngine

engine = CdcEngine()

# Only needed when a checksum=NONE byte stream starts after its FDE:
# engine.set_checksum_enabled(False)

# Feed raw binlog bytes
engine.feed(binlog_chunk)

while (event := engine.next_event()) is not None:
    print(event.type, event.database, event.table)
    print("before:", event.before)
    print("after:", event.after)

Streaming from MySQL

import asyncio
from mysql_event_stream import CdcStream

async def main():
    async for event in CdcStream(
        host="127.0.0.1",
        port=3306,
        user="replicator",
        password="secret",
    ):
        print(f"{event.type.name} {event.database}.{event.table}")
        print(f"  before: {event.before}")
        print(f"  after:  {event.after}")

asyncio.run(main())

Event Format

Each ChangeEvent contains the event type, database/table name, binlog position, and row data as a plain dict keyed by column name:

ChangeEvent(
    type=EventType.UPDATE,
    database="mydb",
    table="users",
    before={"id": 1, "name": "Alice", "score": 42},
    after={"id": 1, "name": "Alice", "score": 100},
    timestamp=1773584164,
    position=BinlogPosition(file="mysql-bin.000003", offset=3611),
)

Thread Safety

CdcEngine instances are single-owner objects. Do not call feed(), next_event(), reset(), or filter/configuration methods concurrently on the same engine instance. Use one engine per thread/task or serialize access externally.

CdcStream uses an internal reader thread through the native binlog client. Iteration and connection lifecycle operations should be owned by one task. Cancellation should go through the stream/client stop path instead of calling other lifecycle methods concurrently.

Features

  • Native performance — C++ core with ctypes FFI, >100k events/sec
  • Zero native dependencies — No libmysqlclient required; only OpenSSL
  • Streaming — Process events incrementally as bytes arrive
  • MySQL 8.4+ — Supports LTS and Innovation releases
  • MariaDB 10.11+ — Auto-detects flavor and handles MariaDB binlog protocol (GTID events type 162, ANNOTATE_ROWS, slave capability negotiation)
  • GTID support — Native BinlogClient with GTID-based replication (MySQL uuid:gno and MariaDB domain-server-seq formats)
  • Row-level events — Full before/after column values for INSERT, UPDATE, DELETE
  • VECTOR type — Native support for MySQL 9.0+ VECTOR columns (decoded as raw bytes)
  • Column names — Automatic column name resolution via metadata queries
  • SSL/TLS — Full SSL/TLS support for secure MySQL connections
  • Backpressure — Internal reader thread with bounded event queue (default 10,000)
  • Auto-reconnection — Automatic reconnection with linear backoff on connection loss

Server Requirements

MySQL:

  • Version: 8.4+
  • GTID mode enabled (for BinlogClient)
  • Replication privileges: REPLICATION SLAVE, REPLICATION CLIENT

MariaDB:

  • Version: 10.11+ (tested against 10.11 and 11.4)
  • GTID replication enabled (log_bin in ROW format)
  • Replication privileges: REPLICATION SLAVE, REPLICATION CLIENT

License

Apache-2.0

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

mysql_event_stream-1.5.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (3.2 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

mysql_event_stream-1.5.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (3.5 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

mysql_event_stream-1.5.0-py3-none-macosx_15_0_x86_64.whl (2.4 MB view details)

Uploaded Python 3macOS 15.0+ x86-64

mysql_event_stream-1.5.0-py3-none-macosx_15_0_arm64.whl (2.7 MB view details)

Uploaded Python 3macOS 15.0+ ARM64

File details

Details for the file mysql_event_stream-1.5.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for mysql_event_stream-1.5.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 552ffe1616592653a2ed586a6301f852aeff352f7acf6eb4311dc7ed24f62825
MD5 d358321b1f49f79d64971d5599386207
BLAKE2b-256 9229c84da6d9a1fa3799bfb8ac7ba1e42fb9f5312f047160ba355c5381bb257e

See more details on using hashes here.

Provenance

The following attestation bundles were made for mysql_event_stream-1.5.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl:

Publisher: publish.yml on libraz/mysql-event-stream

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mysql_event_stream-1.5.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for mysql_event_stream-1.5.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 f8946c30aadebb66565de4dab44889643af9a34ebc17ad81edd1f924673fc135
MD5 a45ec7f365820a0c9ad337aac40273c4
BLAKE2b-256 6a0935277cbdf2305f5df84b7ba1eeb843d07a6110ab2ea4c6e97f9675dac81e

See more details on using hashes here.

Provenance

The following attestation bundles were made for mysql_event_stream-1.5.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl:

Publisher: publish.yml on libraz/mysql-event-stream

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mysql_event_stream-1.5.0-py3-none-macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for mysql_event_stream-1.5.0-py3-none-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 ef08eaab9754e677e3881ef6a7e33921cb522316d95eb0e03046508b5c2bb772
MD5 9762f8bac62ff96a97f1efac813de333
BLAKE2b-256 eb4e10defebb3133f08315c0287931761f0eaf26f8cfe7aebd9caf62c850d73a

See more details on using hashes here.

Provenance

The following attestation bundles were made for mysql_event_stream-1.5.0-py3-none-macosx_15_0_x86_64.whl:

Publisher: publish.yml on libraz/mysql-event-stream

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mysql_event_stream-1.5.0-py3-none-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for mysql_event_stream-1.5.0-py3-none-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 e0350477d7dde667bd9c6a471e298e1e51a5f16a7ba3c505229572685664bdcd
MD5 f94a7b1e81b30dfe0723dc9fda2bdad7
BLAKE2b-256 23ba3e2d7b482242f2f75ba743d63488e37849789708149adbdfe7aed1122956

See more details on using hashes here.

Provenance

The following attestation bundles were made for mysql_event_stream-1.5.0-py3-none-macosx_15_0_arm64.whl:

Publisher: publish.yml on libraz/mysql-event-stream

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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