Skip to main content

mysql-event-stream

An embeddable CDC engine for MySQL 8.4+ and MariaDB 10.11+, as a Python package over a ctypes FFI. It reads the binary log as a replica would and emits row-level change events. No libmysqlclient: the wire protocol is implemented directly in the bundled C++ core.

CI PyPI npm License Python MySQL MariaDB Platform

Install

pip install mysql-event-stream

Python 3.11 or later, no runtime dependencies, typed. Platform wheels are published for Linux x86_64 and aarch64 (recommended for servers) and macOS 15.0 or newer on x86_64 and arm64.

Usage

import os

from mysql_event_stream import CdcStream


async def run() -> None:
    async with CdcStream(
        host="mysql.example.com",
        user="replicator",
        password=os.environ["MYSQL_PASSWORD"],
        server_id=1001,
        include_databases=["shop"],
        start_gtid=await load_checkpoint(),
    ) as stream:
        async for event in stream:
            print(event.type, f"{event.database}.{event.table}")
            await handle(event)  # idempotent
            # "" means no checkpoint yet; never persist it as a start position.
            if checkpoint := stream.current_gtid:
                await save_checkpoint(checkpoint)

An UPDATE arrives with both images of the row. type is the EventType.UPDATE enum member, not the string "UPDATE" — compare it with ==, not against a string:

ChangeEvent(
    type=EventType.UPDATE,
    database="shop",
    table="items",
    before={"id": 8, "name": "Widget", "value": 42},
    after={"id": 8, "name": "Widget", "value": 100},
    timestamp=1773584164,
    position=BinlogPosition(file="mysql-bin.000003", offset=3611),
    names_resolved=True,
    source_sql="",
)

CdcStream is the surface most applications want. Under it, BinlogClient owns the connection and hands back raw event bytes, and CdcEngine decodes binlog bytes from any source with no socket and no thread of its own. Bytes must start at an event boundary; a raw binlog file opens with a 4-byte magic number that has to be skipped first:

from mysql_event_stream import CdcEngine

# The engine holds native state, so scope it rather than waiting for the
# garbage collector to release it.
with CdcEngine() as engine:
    offset = 0
    while offset < len(chunk) or engine.has_events():
        while (event := engine.next_event()) is not None:
            print(event.type, event.database, event.table)

        if offset < len(chunk):
            offset += engine.feed(chunk[offset:])

Server requirements

MySQL 8.4+ or MariaDB 10.11+, logging in row format with binlog_row_image=FULL and GTIDs enabled, and an account with REPLICATION SLAVE and REPLICATION CLIENT. Column names need either binlog_row_metadata=FULL or a SELECT grant on the streamed tables. On MariaDB, set binlog_row_metadata=MINIMAL or FULL: its default NO_LOG delivers text columns as bytes.

Server setup has the full configuration, the grants, and the replica identity rule that two processes on defaults will violate.

Documentation

Development

The binding is managed with Rye; requirements.lock and requirements-dev.lock are the source of truth for the development environment.

cd bindings/python
rye sync
rye run pytest

MES_LIB_PATH selects a specific libmes, which is what a source checkout needs when several builds are present.

Also available

npm install @libraz/mysql-event-stream  # Node.js binding

License

Apache-2.0. Each wheel includes it, and the license texts of the statically linked OpenSSL and zlib, in its .dist-info/licenses/.

Metadata

Release files for mysql-event-stream 1.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for mysql-event-stream 1.8.0
File Actions
mysql_event_stream-1.8.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64 Details for mysql_event_stream-1.8.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
mysql_event_stream-1.8.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details for mysql_event_stream-1.8.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
mysql_event_stream-1.8.0-py3-none-macosx_15_0_x86_64.whl Python 3 none macOS 15.0+ x86-64 Details for mysql_event_stream-1.8.0-py3-none-macosx_15_0_x86_64.whl
mysql_event_stream-1.8.0-py3-none-macosx_15_0_arm64.whl Python 3 none macOS 15.0+ ARM64 Details for mysql_event_stream-1.8.0-py3-none-macosx_15_0_arm64.whl

Total release size: 12.1 MB

Release files / mysql_event_stream-1.8.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL mysql_event_stream-1.8.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 3.3 MB
Tags Linux glibc 2.17+ x86-64 Python 3
SHA-256 checksum
How to use checksums
c1a2b0d8ef91c1eee0572a9381d755ba69ba1e1dae381b1c91d1aca3fecc3f2c
BLAKE2b-256 checksum
How to use checksums
a2641b5b963f7bacfd96429ba825df3bf9b996f76bef08baf0a2ad1040672048
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.

Transparency log

Release files / mysql_event_stream-1.8.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL mysql_event_stream-1.8.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 3.6 MB
Tags Linux glibc 2.17+ ARM64 Python 3
SHA-256 checksum
How to use checksums
2749baddb8e7f8b65be28100f52b6aea97ba338c7af23ea098484261ea26e97d
BLAKE2b-256 checksum
How to use checksums
a310a9c3601e886c5caacc581b0d0acec1bf834f8c091bf522985b3202b4ff7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.

Transparency log

Release files / mysql_event_stream-1.8.0-py3-none-macosx_15_0_x86_64.whl

Download URL mysql_event_stream-1.8.0-py3-none-macosx_15_0_x86_64.whl
Size 2.5 MB
Tags Python 3 macOS 15.0+ x86-64
SHA-256 checksum
How to use checksums
cb2e176e62d4c9b187da1f94a3c0ff2e5bee5054f920014d53b2d5a7e3f70856
BLAKE2b-256 checksum
How to use checksums
51c79ba86a03ee9d5b0e47f71124b5998a8cd7979ee8d93ec53dff3bb8b334bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.

Transparency log

Release files / mysql_event_stream-1.8.0-py3-none-macosx_15_0_arm64.whl

Download URL mysql_event_stream-1.8.0-py3-none-macosx_15_0_arm64.whl
Size 2.7 MB
Tags Python 3 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
1e5d50e11e72c8a6e3eb97b8658b6153c740db097b8bdcb3b717159227dee854
BLAKE2b-256 checksum
How to use checksums
a1379211b9f2ea6f8b4eda7f9373b9498e9ecb36ea025c011e965486c7f62e60
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.

Transparency log

Security for mysql-event-stream 1.8.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 4 files in this release have been uploaded with provenance metadata.

Select from 4 files

Attestation for mysql_event_stream-1.8.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page