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.
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
await save_checkpoint(stream.current_gtid)
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):
consumed = engine.feed(chunk[offset:])
offset += consumed
# Nothing consumed and nothing queued: the tail is a partial
# event. Keep chunk[offset:] and prepend it to the next chunk.
if consumed == 0 and not engine.has_events():
break
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.
Server setup has the full configuration, the grants, and the replica identity rule that two processes on defaults will violate.
Documentation
- Python API — every class, option and default.
- Getting started and Examples.
- Change events and Column values — what arrives, and as what type.
- Checkpoints and recovery, Errors, Threading and lifecycle.
- Introduction indexes the rest.
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
Metadata
Release files for mysql-event-stream 1.7.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| mysql_event_stream-1.7.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl | Python 3 | none | Linux glibc 2.17+ x86-64 | Details |
| mysql_event_stream-1.7.1-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl | Python 3 | none | Linux glibc 2.17+ ARM64 | Details |
| mysql_event_stream-1.7.1-py3-none-macosx_15_0_x86_64.whl | Python 3 | none | macOS 15.0+ x86-64 | Details |
| mysql_event_stream-1.7.1-py3-none-macosx_15_0_arm64.whl | Python 3 | none | macOS 15.0+ ARM64 | Details |
Total release size: 12.0 MB
Release files / mysql_event_stream-1.7.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | mysql_event_stream-1.7.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 |
8b919507e2f8b4d4220e83557623ce3c282749cf2c21a337c4f8a9795d94d888
|
|
BLAKE2b-256 checksum How to use checksums |
40de110ec8d5d5a354283e70f3e8811d45bdab76478fd9c1a9b0f5ef0b21359e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 29, 2026.
Transparency logRelease files / mysql_event_stream-1.7.1-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
| Download URL | mysql_event_stream-1.7.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 |
9062b48bc75a49c0f6b6198d75f97f4e4e3003dc21f95666a74b2d55d6fbaad4
|
|
BLAKE2b-256 checksum How to use checksums |
cce82e3102ca46a8c0efb30f6178d3cc35848f559ef1528d05ec896440131e60
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 29, 2026.
Transparency logRelease files / mysql_event_stream-1.7.1-py3-none-macosx_15_0_x86_64.whl
| Download URL | mysql_event_stream-1.7.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 |
d09d791586b28ee1cb0c7b479f29525ee7fc35f82301c604db8952f86a3b4f0e
|
|
BLAKE2b-256 checksum How to use checksums |
00d85e57ebaf92ebfb71466ab7445df0141ff28986054924889280fffe8a26b1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 29, 2026.
Transparency logRelease files / mysql_event_stream-1.7.1-py3-none-macosx_15_0_arm64.whl
| Download URL | mysql_event_stream-1.7.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 |
8a007d962225f9dd2a5dad10705e1332452a590f4261f2515d59163ca19c743c
|
|
BLAKE2b-256 checksum How to use checksums |
f915f2ba2ef4f7aa29e212bcd6abbdf8f2fb27bbde1b1eeba07a83a41c6fd8e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 29, 2026.
Transparency log