zerobus-sdk / python
CLAUDE.md94 starsChanged 10 days agoApache-2.0View on GitHub
Python wrapper around the Rust core via PyO3 and maturin. When writing or reviewing client code that uses this SDK, follow the cross-SDK performance flow from the root CLAUDE.md: - Idiomatic flow: ingest in a loop with ingest_record_offset(), or prefer ingest_records_offset() for bulk data, then call flush() once to confirm durability. ingest_record_offset() returns as soon as the record is queued; the SDK sends it and tracks its acknowledgment in the background. Do not feature ingest_record_nowait() in examples: it spawns a…
In this repository6 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- cpp/CLAUDE.mdCLAUDE.md
- go/CLAUDE.mdCLAUDE.md
- java/CLAUDE.mdCLAUDE.md
- rust/CLAUDE.mdCLAUDE.md
- typescript/CLAUDE.mdCLAUDE.md
The file
We split this CLAUDE.md into the rules it gives an agent
5 rules. About 0 are common, 1 is distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 7
When writing or reviewing client code that uses this SDK, follow the cross-SDK performance flow from the root CLAUDE.md:
- Very specific: line 82
Every PR must update python/NEXT_CHANGELOG.md under the appropriate section if it changes user-facing behavior.
- Very specific: line 83
Update python/README.md if the change affects usage, setup, or API surface.
- Very specific: line 84
Add or update examples in python/examples/ for new or modified APIs.
- Very specific: line 85
Add docstrings for all new public classes/methods.
≈ “Common” is an estimate: at least 1 in 5 of the 26,980 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Python SDK
Python wrapper around the Rust core via PyO3 and maturin.
Client code patterns
When writing or reviewing client code that uses this SDK, follow the cross-SDK
performance flow from the root CLAUDE.md:
- Idiomatic flow: ingest in a loop with
ingest_record_offset(), or preferingest_records_offset()for bulk data, then callflush()once to confirm durability.ingest_record_offset()returns as soon as the record is queued; the SDK sends it and tracks its acknowledgment in the background. Do not featureingest_record_nowait()in examples: it spawns a detached task and is not safely synchronized withflush(). - In async code, an
AckCallbackis a good way to track durability without blocking. wait_for_offset()blocks until a specific offset is acknowledged — use it to confirm a specific record before continuing. Acks are ordered, so waiting on the LAST offset confirms all prior records. Avoid calling it after every record in a tight loop, since that limits throughput to one record per round-trip.ingest_record()is deprecated — prefer the offset-based APIs.
Structure
python/
├── rust/src/lib.rs # PyO3 bindings (the Rust ↔ Python bridge)
├── zerobus/ # Python package (pure-Python layer over _zerobus_core)
├── tests/ # pytest test suite
└── pyproject.toml # Build config (maturin)The native extension module is _zerobus_core, exposed as three submodules:
zerobus._zerobus_core.sync— Synchronous APIzerobus._zerobus_core.aio— Async API (Pythonasync/await)zerobus._zerobus_core.arrow— Arrow Flight support
Build commands
Run from python/:
make dev— Create venv, install deps, build Rust extensionmake build-rust— Release build of the Rust extensionmake develop-rust— Debug build (faster iteration)make test— pytest with coveragemake lint— pycodestyle + autoflakemake fmt— black + autoflake + isort
Features
Avro record format support is always compiled in — the avro feature is enabled on the
databricks-zerobus-ingest-sdk dependency in python/rust/Cargo.toml. The avro pip
extra installs fastavro, which is required only for encoding dict records; pre-encoded
Avro bytes need no extra.
FFI boundary: PyO3
PyO3 handles memory management automatically via Python reference counting. Key considerations:
- GIL release: Async operations release the GIL, allowing concurrent Python threads. The tokio runtime is initialized at module import via
pyo3_async_runtimes::tokio::init(). - PyO3 API: The bindings use PyO3 0.29 and the
Bound<'py, T>API. UsePython::attach(notwith_gil),Python::detach(notallow_threads), andcast(notdowncast).Py<T>is not unconditionallyClone— useclone_ref(py)under an attached interpreter. - Object lifetime: PyO3 classes are ref-counted by Python's GC. No explicit free needed, but
close()should still be called to flush pending records before GC cleanup. - Error mapping: Rust
ZerobusErrormaps toZerobusException/NonRetriableExceptionPython exception classes. - Serialization: Proto descriptors and record payloads cross as Python
bytes. JSON records cross as Pythonstr. No extra serialization layer — PyO3 handles the conversion.
Breaking change rules
The public Python API is defined by the classes and functions in zerobus/. Changes here follow semver:
- Removing a class, method, or parameter is breaking.
- Deprecate with
warnings.warn(..., DeprecationWarning)first. - The PyO3 binding layer (
python/rust/src/lib.rs) is internal; refactoring it is safe as long as the Python-facing API doesn't change.
Performance notes
- PyO3 has minimal overhead for
bytes/strpayloads (no copy for immutable buffers). - Async API avoids GIL contention — prefer it for high-throughput ingestion.
- Batch ingestion (
ingest_records) amortizes the Python→Rust call overhead.
Changelog and documentation
- Every PR must update
python/NEXT_CHANGELOG.mdunder the appropriate section if it changes user-facing behavior. - Update
python/README.mdif the change affects usage, setup, or API surface. - Add or update examples in
python/examples/for new or modified APIs. - Add docstrings for all new public classes/methods. Update type stubs (
_zerobus_core.pyi) if the native module interface changes.
Release
- Version is derived from
python/rust/Cargo.tomlvia maturin (no separate Python version file). - Tag:
python/v<semver>→ triggersrelease-python.yml→ builds wheels for all platforms/Python versions → publishes to PyPI. - On version bump PR: update the version in
python/rust/Cargo.toml, moveNEXT_CHANGELOG.mdcontents toCHANGELOG.md, resetNEXT_CHANGELOG.md.
Config
- Python >= 3.9 required; tested through 3.14 (free-threaded builds are not supported)
- Rust >= 1.88 required for the wrapper crate (Tonic 0.14.6 MSRV)
- Line length: 120 (black)
- Formatter: black, isort
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

