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.1

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.1
File Actions
mysql_event_stream-1.8.1-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.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
mysql_event_stream-1.8.1-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details for mysql_event_stream-1.8.1-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
mysql_event_stream-1.8.1-py3-none-macosx_15_0_x86_64.whl Python 3 none macOS 15.0+ x86-64 Details for mysql_event_stream-1.8.1-py3-none-macosx_15_0_x86_64.whl
mysql_event_stream-1.8.1-py3-none-macosx_15_0_arm64.whl Python 3 none macOS 15.0+ ARM64 Details for mysql_event_stream-1.8.1-py3-none-macosx_15_0_arm64.whl

Total release size: 12.1 MB

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

Download URL mysql_event_stream-1.8.1-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
5cb0077616dad5b1e7a072af1d2f6669221594c1c8ed34262f85710121f8c3df
BLAKE2b-256 checksum
How to use checksums
c18febb17a40e7c9bab954abb6067fd161931d953e3db00220c0c927ce97419a
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 Nov 3, 2026.

Transparency log

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

Download URL mysql_event_stream-1.8.1-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
d54bc125e8f85416a70ed455f3a570130448e053cc6e142d0c2026ae5931c27c
BLAKE2b-256 checksum
How to use checksums
b29da095c778c8a1dfe40d77ce2d3470a3a980ea8ab059871006d68ad5edae35
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 Nov 3, 2026.

Transparency log

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

Download URL mysql_event_stream-1.8.1-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
0647a8123c610c2b779c95312824c86e84183c46f2037ceb1e60130488fcc94d
BLAKE2b-256 checksum
How to use checksums
a123ee283a331a68bb3c9b99a42d95fec80b0c870230306e0a1500c301610615
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 Nov 3, 2026.

Transparency log

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

Download URL mysql_event_stream-1.8.1-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
7d593a71208b4a9b08cdeb8038185beb1a4630ac15485c076d432a644dc68e7e
BLAKE2b-256 checksum
How to use checksums
2127b07a3710a69a64ae3f1aec7e5fd62c654cbad089dd180b81ed81740840cf
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 Nov 3, 2026.

Transparency log

Security for mysql-event-stream 1.8.1

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.1-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 Nov 3, 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