High-performance Python client for Rivven distributed streaming platform
Project description
rivven-python
High-performance Python bindings for the Rivven event streaming platform.
Features
- Native Performance: Zero-copy message handling through Rust bindings (PyO3)
- Async-First: Full async/await support with Python's asyncio
- Type-Safe: Complete type annotations for IDE support
- Transaction Support: Exactly-once semantics with transactional producers
- Authentication: Multiple auth methods (simple, SCRAM-SHA-256)
- Admin Operations: Full topic and partition management
Installation
pip install rivven
Usage
Basic Connection
import asyncio
import rivven
async def main():
# Connect to Rivven cluster
client = await rivven.connect("localhost:9092")
# Create a topic
await client.create_topic("my-topic", partitions=3)
# List topics
topics = await client.list_topics()
print(f"Topics: {topics}")
asyncio.run(main())
Producer
import asyncio
import rivven
async def produce():
client = await rivven.connect("localhost:9092")
producer = client.producer("my-topic")
# Send a message
offset = await producer.send(b'{"event": "login"}', key=b"user-123")
print(f"Sent at offset: {offset}")
# Send to specific partition
await producer.send_to_partition(b"value", partition=0, key=b"key")
# Batch send for better throughput
offsets = await producer.send_batch([b"msg1", b"msg2", b"msg3"])
asyncio.run(produce())
Consumer
import asyncio
import rivven
async def consume():
client = await rivven.connect("localhost:9092")
consumer = client.consumer("my-topic", group_id="my-group")
# Fetch messages
messages = await consumer.fetch(max_messages=100)
for msg in messages:
print(f"Offset {msg.offset}: {msg.value_str()}")
# Commit offsets
await consumer.commit()
# Or use async iterator
async for msg in consumer:
print(f"Received: {msg.value_str()}")
await consumer.commit()
asyncio.run(consume())
Admin Operations
import asyncio
import rivven
async def admin():
client = await rivven.connect("localhost:9092")
# Create topic
await client.create_topic("new-topic", partitions=3, replication_factor=1)
# List topics
topics = await client.list_topics()
print(f"Topics: {topics}")
# Get topic configuration
configs = await client.describe_topic_configs("new-topic")
print(f"Configs: {configs}")
# Modify topic configuration
await client.alter_topic_config("new-topic", "retention.ms", "86400000")
# Add partitions
await client.create_partitions("new-topic", new_total=6)
# Get offset for timestamp
offset = await client.get_offset_for_timestamp("new-topic", 0, 1699900000000)
# Delete records before offset
await client.delete_records("new-topic", 0, before_offset=100)
# Delete topic
await client.delete_topic("old-topic")
asyncio.run(admin())
Authentication
import asyncio
import rivven
async def authenticated():
client = await rivven.connect("localhost:9092")
# Simple authentication
await client.authenticate("username", "password")
# Or SCRAM-SHA-256 authentication
await client.authenticate_scram("username", "password")
# Use client as normal
topics = await client.list_topics()
asyncio.run(authenticated())
TLS Connection
import asyncio
import rivven
async def secure():
# Connect with TLS
client = await rivven.connect_tls(
"localhost:9093",
ca_cert="/path/to/ca.crt",
client_cert="/path/to/client.crt", # Optional: mTLS
client_key="/path/to/client.key", # Optional: mTLS
)
topics = await client.list_topics()
asyncio.run(secure())
Transactions (Exactly-Once Semantics)
import asyncio
import rivven
async def transactional():
client = await rivven.connect("localhost:9092")
# Initialize transactional producer - returns a ProducerState object
producer_state = await client.init_producer_id("my-txn-id")
print(f"Producer ID: {producer_state.producer_id}, Epoch: {producer_state.producer_epoch}")
try:
# Begin transaction
await client.begin_transaction("my-txn-id", producer_state)
# Add partitions to transaction
await client.add_partitions_to_txn("my-txn-id", producer_state, [
("my-topic", 0),
("my-topic", 1),
])
# Publish with idempotent semantics - sequence is auto-incremented
await client.publish_idempotent(
topic="my-topic",
value=b"message-1",
producer_state=producer_state,
key=b"key-1"
)
await client.publish_idempotent(
topic="my-topic",
value=b"message-2",
producer_state=producer_state,
key=b"key-2"
)
# Commit transaction
await client.commit_transaction("my-txn-id", producer_state)
except Exception as e:
# Abort on error
await client.abort_transaction("my-txn-id", producer_state)
raise
asyncio.run(transactional())
Exception Handling
Rivven provides a hierarchy of exception types for granular error handling:
from rivven import (
RivvenException, # Base exception for all Rivven errors
ConnectionException, # Connection-related errors
ServerException, # Server-side errors
TimeoutException, # Request timeouts
SerializationException, # Serialization/deserialization errors
ConfigException, # Configuration errors
)
try:
client = await rivven.connect("localhost:9092")
except ConnectionException as e:
print(f"Failed to connect: {e}")
except TimeoutException as e:
print(f"Connection timed out: {e}")
except RivvenException as e:
print(f"General Rivven error: {e}")
Testing
Running Tests
# Install test dependencies
pip install -r requirements-test.txt
# Run API tests (no broker required)
pytest tests/test_api.py -v
# Run integration tests (requires running broker)
export RIVVEN_BROKER="localhost:9092"
pytest tests/test_integration.py -v -m integration
Type Checking
The package includes type stubs (rivven.pyi) for IDE support and static type checking:
pip install mypy
mypy your_code.py
Building from Source
# Install maturin
pip install maturin
# Build wheel
cd crates/rivven-python
maturin build --release
# Install locally
pip install target/wheels/rivven-*.whl
# Development install (editable)
maturin develop --release
Documentation
License
Apache-2.0. See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rivven-0.0.13-cp312-cp312-manylinux_2_28_aarch64.whl.
File metadata
- Download URL: rivven-0.0.13-cp312-cp312-manylinux_2_28_aarch64.whl
- Upload date:
- Size: 804.7 kB
- Tags: CPython 3.12, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
800f324b3b834d0fdfe2e03d7d91972336fa13cb862794e51c156a469668ab60
|
|
| MD5 |
cd6243cc738c037459463bc15900d604
|
|
| BLAKE2b-256 |
2a720703129a3ff38bbc31b1ef6161772f6bd406d0a2ecdd14c87fdc692ebe7e
|
Provenance
The following attestation bundles were made for rivven-0.0.13-cp312-cp312-manylinux_2_28_aarch64.whl:
Publisher:
release.yml on hupe1980/rivven
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rivven-0.0.13-cp312-cp312-manylinux_2_28_aarch64.whl -
Subject digest:
800f324b3b834d0fdfe2e03d7d91972336fa13cb862794e51c156a469668ab60 - Sigstore transparency entry: 941760953
- Sigstore integration time:
-
Permalink:
hupe1980/rivven@c8fb0df06f53ccf760ab0752d2edb183c35873ad -
Branch / Tag:
refs/tags/v0.0.13 - Owner: https://github.com/hupe1980
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c8fb0df06f53ccf760ab0752d2edb183c35873ad -
Trigger Event:
push
-
Statement type:
File details
Details for the file rivven-0.0.13-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: rivven-0.0.13-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 834.8 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5489e1c3b153412974adc9c747366ea0da4a81e7705120a9b159398fdf56080
|
|
| MD5 |
07767b03f368047fee12a1002268aeff
|
|
| BLAKE2b-256 |
68e94cca7d6ad68d1c48964ae5ff8ed006b65da4b8fb94fdb3f14d23d4239362
|
Provenance
The following attestation bundles were made for rivven-0.0.13-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release.yml on hupe1980/rivven
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rivven-0.0.13-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
a5489e1c3b153412974adc9c747366ea0da4a81e7705120a9b159398fdf56080 - Sigstore transparency entry: 941760934
- Sigstore integration time:
-
Permalink:
hupe1980/rivven@c8fb0df06f53ccf760ab0752d2edb183c35873ad -
Branch / Tag:
refs/tags/v0.0.13 - Owner: https://github.com/hupe1980
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c8fb0df06f53ccf760ab0752d2edb183c35873ad -
Trigger Event:
push
-
Statement type:
File details
Details for the file rivven-0.0.13-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: rivven-0.0.13-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 761.5 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f591d20303d471b296a6735932af158e9892315c8ce4c5faf2079a7597e2a9ba
|
|
| MD5 |
0cc8a9b469bf11d498d3db62f0243fe5
|
|
| BLAKE2b-256 |
be305e41009cdd52c6adbe0d6bd2284e2af1df8cabf6c588890fa2b2b91d8d88
|
Provenance
The following attestation bundles were made for rivven-0.0.13-cp312-cp312-macosx_11_0_arm64.whl:
Publisher:
release.yml on hupe1980/rivven
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rivven-0.0.13-cp312-cp312-macosx_11_0_arm64.whl -
Subject digest:
f591d20303d471b296a6735932af158e9892315c8ce4c5faf2079a7597e2a9ba - Sigstore transparency entry: 941760916
- Sigstore integration time:
-
Permalink:
hupe1980/rivven@c8fb0df06f53ccf760ab0752d2edb183c35873ad -
Branch / Tag:
refs/tags/v0.0.13 - Owner: https://github.com/hupe1980
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c8fb0df06f53ccf760ab0752d2edb183c35873ad -
Trigger Event:
push
-
Statement type: