Python bindings for Eclipse uProtocol Rust implementation
Project description
up-py-rs
Python bindings for the Eclipse uProtocol Rust implementation (up-rust). This package provides high-performance Python APIs for uProtocol communication patterns by leveraging Rust's speed and safety.
Features
- 🚀 High Performance: Rust-powered implementations with minimal Python overhead
- 🔒 Type Safe: Full type hints and stub files for excellent IDE support
- 📡 Complete uProtocol Support: Publishers, Notifiers, and Transport implementations
- 🐍 Pythonic API: Easy-to-use interfaces that feel natural in Python
- ⚡ Async Ready: Built on Tokio async runtime for efficient I/O operations
Installation
Install from PyPI:
# Basic installation (includes LocalTransport and core features)
pip install up-py-rs
# With Zenoh network transport
pip install up-py-rs[zenoh]
# With all optional features
pip install up-py-rs[all]
Or using uv:
uv add up-py-rs
# or with extras
uv add up-py-rs --extra zenoh
Optional Dependencies
up-py-rs supports modular installation through extras:
| Extra | Description | Install Command |
|---|---|---|
zenoh |
Zenoh network transport | pip install up-py-rs[zenoh] |
discovery |
Service discovery support | pip install up-py-rs[discovery] |
subscription |
Advanced subscription management | pip install up-py-rs[subscription] |
twin |
Digital twin support | pip install up-py-rs[twin] |
cloudevents |
CloudEvents format support | pip install up-py-rs[cloudevents] |
all |
All optional features | pip install up-py-rs[all] |
test |
Testing utilities | pip install up-py-rs[test] |
Note: Currently all Rust features are included in the wheel. Extras are provided for documentation and future Python runtime dependencies.
Quick Start
Simple Publisher (Local Transport)
For in-process communication without network overhead:
from up_py_rs import StaticUriProvider
from up_py_rs.local_transport import LocalTransport
from up_py_rs.communication import SimplePublisher, UPayload
# Setup
uri_provider = StaticUriProvider("my-vehicle", 0xa34b, 0x01)
transport = LocalTransport()
publisher = SimplePublisher(transport, uri_provider)
# Publish a message
payload = UPayload.from_string("Hello from Python!")
publisher.publish(0xb4c1, payload)
Zenoh Publisher (Network Transport)
For distributed communication across network boundaries:
from up_py_rs import StaticUriProvider
from up_py_rs.zenoh_transport import UPTransportZenoh
from up_py_rs.communication import SimplePublisher, UPayload
# Setup Zenoh transport
uri_provider = StaticUriProvider("publisher", 0x3b1da, 1)
transport = UPTransportZenoh.builder("publisher").build()
publisher = SimplePublisher(transport, uri_provider)
# Publish messages
for i in range(1, 11):
payload = UPayload.from_string(f"event {i}")
publisher.publish(0x8001, payload)
Note: Requires pip install up-py-rs[zenoh]
Simple Notifier
from up_py_rs import StaticUriProvider
from up_py_rs.local_transport import LocalTransport
from up_py_rs.communication import SimpleNotifier, UPayload
def notification_handler(msg):
text = msg.extract_string()
if text:
print(f"Received: {text}")
# Setup
uri_provider = StaticUriProvider("my-vehicle", 0xa34b, 0x01)
transport = LocalTransport()
notifier = SimpleNotifier(transport, uri_provider)
# Register listener
topic = uri_provider.get_resource_uri(0xd100)
notifier.start_listening(topic, notification_handler)
# Send notification
payload = UPayload.from_string("Alert!")
destination = uri_provider.get_source_uri()
notifier.notify(0xd100, destination, payload)
# Cleanup
notifier.stop_listening(topic, notification_handler)
Components
LocalTransport
In-process message transport for testing and local communication without network overhead. Best for single-process applications and testing.
UPTransportZenoh
Zenoh-based network transport for distributed communication across network boundaries. Enables pub/sub patterns between different processes, devices, or vehicles. Requires zenoh extra.
StaticUriProvider
Creates and manages uProtocol URIs for identifying entities in the network.
SimplePublisher
High-level API for publishing messages to specific resources. Works with any transport (Local or Zenoh).
SimpleNotifier
Send and receive notifications between uEntities with listener callbacks.
UPayload
Message payload wrapper supporting strings and raw bytes with protobuf format.
Development
Building from Source
Requirements:
- Python 3.8+
- Rust toolchain (for building)
- uv or pip
# Clone the repository
git clone https://github.com/sachinkum0009/up-py-rs.git
cd up-py-rs
# Build in development mode
uv run maturin develop
# Run tests
uv run pytest
# Run examples
uv run python examples/simple_publish.py
uv run python examples/simple_notify.py
# Run Zenoh example (requires zenoh extra)
uv add up-py-rs --extra zenoh
uv run python examples/simple_zenoh_publisher.py
Building Wheels
# Build release wheel
uv run maturin build --release
# Build and publish to PyPI
uv run maturin publish
Architecture
up-py-rs bridges Python and Rust using PyO3:
- Rust Core: High-performance implementations from up-rust
- PyO3 Bindings: Zero-cost abstractions between Python and Rust
- Python API: Pythonic interfaces with full type hints
Each async operation maintains its own Tokio runtime for thread-safe execution across the Python/Rust boundary.
Contributing
Contributions are welcome! Please see the contribution guidelines for details.
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Links
Acknowledgments
Built with:
- Eclipse uProtocol - The underlying protocol specification
- PyO3 - Rust bindings for Python
- Maturin - Build tool for Rust/Python projects
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 Distribution
Built Distribution
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 up_py_rs-0.0.8.tar.gz.
File metadata
- Download URL: up_py_rs-0.0.8.tar.gz
- Upload date:
- Size: 61.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ee67e5e086c0f45aa84f5cc2577a52858725c676e79ff219c38ce03e198c5f0
|
|
| MD5 |
3bf33e6312ace6005c877971fe673776
|
|
| BLAKE2b-256 |
2691d4ff49c63c787c59bdf4d3ec577fefd5f5bd2bdef1dc69e9743d0e98f600
|
File details
Details for the file up_py_rs-0.0.8-cp38-abi3-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: up_py_rs-0.0.8-cp38-abi3-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.8+, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
11e2cf73e6bf71582253af51c8c38406e7641cf6da98907c154bc5247ecd5f24
|
|
| MD5 |
6801cf839cee295670f8d991872d7b80
|
|
| BLAKE2b-256 |
f522817cfa2cd37d29fa4ffe3f2622eb9547b51c830f9c939a2402be7da66d6f
|