Skip to main content

Python bindings for Eclipse uProtocol Rust implementation

Project description

up-py-rs

CI Status PyPI version Python 3.8+ License

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 examples (requires zenoh extra)
uv add up-py-rs --extra zenoh

# Terminal 1: Start subscriber
uv run python examples/simple_zenoh_subscriber.py

# Terminal 2: Start publisher
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:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

up_py_rs-0.1.0.tar.gz (63.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

up_py_rs-0.1.0-cp38-abi3-manylinux_2_34_x86_64.whl (7.4 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.34+ x86-64

File details

Details for the file up_py_rs-0.1.0.tar.gz.

File metadata

  • Download URL: up_py_rs-0.1.0.tar.gz
  • Upload date:
  • Size: 63.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.11.5

File hashes

Hashes for up_py_rs-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6d6177cda3b456f159ccb705a4119bd3f1d5749ccfe62799b4f5624d242615d9
MD5 36465b3cbe9b5a98773603b2159adb93
BLAKE2b-256 aa8884461805e701b3d3d9c9918cd4e95f6cdbed257556d3e6071594f95de355

See more details on using hashes here.

File details

Details for the file up_py_rs-0.1.0-cp38-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for up_py_rs-0.1.0-cp38-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 d640de8d07999c5d3b4756aff2fb018940ec9134de19f59414d2d1bad3bbb40b
MD5 94e87d8b48342fc3a78b473de0be5213
BLAKE2b-256 0fac0de5a0dc857b8bead370390b221503f8d339e630da7aeba43b612413881b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page