Please read the top-level CONTRIBUTING.md first for general contribution guidelines, pull request process, and commit requirements.
This document covers Python-specific development setup and workflow.
- Python 3.9 or higher
- Git
- Rust toolchain (required for building the native extension)
- Install from rustup.rs
- Verify:
rustc --version
- maturin (for building Rust-Python bindings)
- Install:
pip install maturin
- Install:
Since v0.3.0, the SDK uses a Rust core with Python bindings built via maturin and PyO3.
-
Clone the repository:
git clone https://github.com/databricks/zerobus-sdk.git cd zerobus-sdk/python -
Create and activate a virtual environment:
make dev
This will:
- Create a virtual environment in
.venv - Install the package in development mode with all dev dependencies
- Note: This uses
pip install -e .which builds the Rust extension automatically
- Create a virtual environment in
-
Activate the virtual environment:
source .venv/bin/activate # On Windows: .venv\Scripts\activate
The SDK's core is implemented in Rust. There are two ways to build it:
Option 1: Development Mode (Recommended for active development)
make develop-rustThis compiles the Rust code in debug mode and installs it directly into your virtual environment. After modifying Rust code, re-run this command to rebuild.
Option 2: Release Mode (For benchmarking or distribution)
make build-rustThis creates an optimized wheel in dist/. Use this for performance testing or creating release builds.
Code style is enforced by a formatter check in your pull request. We use Black to format our code. Run make fmt to ensure your code is properly formatted prior to raising a pull request.
Format your code before committing:
make fmtThis runs:
- Black: Code formatting
- autoflake: Remove unused imports
- isort: Sort imports
Check your code for issues:
make lintThis runs:
- pycodestyle: Style guide enforcement
- autoflake: Check for unused imports
Run the test suite to ensure your changes don't break existing functionality:
make testThis runs:
- pytest: Unit tests with coverage reports
- Generates HTML and XML coverage reports in
htmlcov/andcoverage.xml
Open the coverage report in your browser:
open htmlcov/index.html # macOS
xdg-open htmlcov/index.html # Linux- Update docstrings for all public APIs
- Use Google-style docstrings
- Include examples in docstrings where helpful
- Update README.md for user-facing changes
- Update examples/ for new features
Example docstring:
def ingest_record(self, record) -> RecordAcknowledgment:
"""
Submits a single record for ingestion into the stream.
This method may block if the maximum number of in-flight records
has been reached.
Args:
record: The Protobuf message object to be ingested.
Returns:
RecordAcknowledgment: An object to wait on for the server's acknowledgment.
Raises:
ZerobusException: If the stream is not in a valid state for ingestion.
Example:
>>> record = AirQuality(device_name="sensor-1", temp=25)
>>> ack = stream.ingest_record(record)
>>> ack.wait_for_ack()
"""All pull requests must pass CI checks:
- fmt: Runs formatting checks (black, autoflake, isort)
- lint: Runs linting checks (pycodestyle, autoflake)
- tests-ubuntu: Runs tests on Ubuntu with Python 3.9, 3.10, 3.11, 3.12
- tests-windows: Runs tests on Windows with Python 3.9, 3.10, 3.11, 3.12
The formatting check runs make dev fmt and then checks for any git differences. If there are differences, the check will fail.
You can view CI results in the GitHub Actions tab of the pull request.
make dev- Set up development environment (creates venv, installs deps, builds Rust extension)make install- Install package in editable modemake build- Build wheel package using maturin (usePYTHON=python3.Xto specify version)make install-wheel- Install the built wheelmake fmt- Format code with black, autoflake, and isortmake lint- Run linting with pycodestyle and autoflakemake test- Run unit tests with pytest and generate coverage reportsmake clean- Remove Python build artifacts (dist, egg-info, pytest cache)make clean-all- Remove all build artifacts including Rust and.venvmake help- Show all available targets
make build-rust- Build Rust extension in release mode (optimized, slower compile)make develop-rust- Build Rust extension in debug mode and install to venv (faster compile)make clean-rust- Remove Rust build artifacts
Daily development (Python changes only):
make fmt # Format your code
make lint # Check for issues
make test # Run testsAfter modifying Rust code:
make develop-rust # Rebuild and install Rust extension
make test # Test Python bindingsCreating a release build:
make build # Build optimized wheel
# Wheel will be in dist/The package is published on PyPI as databricks-zerobus-ingest-sdk.