Skip to main content

MySQL 8.4 CDC engine - Python binding (native ctypes)

Project description

mysql-event-stream — Python Binding

CI License

A lightweight MySQL 8.4 CDC (Change Data Capture) engine for Python. 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
  • Linux aarch64
  • macOS ARM64 (Apple Silicon)

Usage

Parsing binlog bytes

from mysql_event_stream import CdcEngine

engine = CdcEngine()

# 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),
)

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 — Built for the latest MySQL LTS release
  • GTID support — Native BinlogClient with GTID-based replication
  • Row-level events — Full before/after column values for INSERT, UPDATE, DELETE
  • 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

MySQL Requirements

  • Version: 8.4
  • Binary log format: ROW (binlog_format=ROW)
  • GTID mode enabled (for BinlogClient)
  • 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.0.0-py3-none-manylinux_2_17_x86_64.whl (2.4 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

mysql_event_stream-1.0.0-py3-none-manylinux_2_17_aarch64.whl (2.2 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

mysql_event_stream-1.0.0-py3-none-macosx_11_0_arm64.whl (2.5 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file mysql_event_stream-1.0.0-py3-none-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for mysql_event_stream-1.0.0-py3-none-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 8459846269134e1108b4712de8e0a810aff5aea0609c5c90997a9c6073bd03f6
MD5 b060cbe9c3bc9fa69c21986a6a42f5cd
BLAKE2b-256 da83c871287a04a686640bb370e5f09e563130fa03745b8d202ae3362a0c4054

See more details on using hashes here.

Provenance

The following attestation bundles were made for mysql_event_stream-1.0.0-py3-none-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.0.0-py3-none-manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for mysql_event_stream-1.0.0-py3-none-manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 ddff633a07f1c578c171ed2ee6c12049e16b8864df216f0ac31d31e4e419f54b
MD5 cfa90a9cb50190112e550af0c99a0d3b
BLAKE2b-256 952994a595f9f0499805a046689e2402f797f32b104722839aca8ab05dfd84a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for mysql_event_stream-1.0.0-py3-none-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.0.0-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mysql_event_stream-1.0.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 caa7378dd2bd8c5d637089a6e2cd41a9bc0565bd93addde3ecbeb5d46a1dd0a8
MD5 cd8076ea2ec608a4c1ebef0a1230246f
BLAKE2b-256 50918ca77b3656c31d12a8e406660481b18a7ea33ab093ea301180afb222bc7d

See more details on using hashes here.

Provenance

The following attestation bundles were made for mysql_event_stream-1.0.0-py3-none-macosx_11_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