Skip to content

Add up_rust_py package with documentation and examples#1

Open
sachinkum0009 wants to merge 25 commits into
eclipse-uprotocol:mainfrom
sachinkum0009:feat/pyo3-rs-bindings
Open

Add up_rust_py package with documentation and examples#1
sachinkum0009 wants to merge 25 commits into
eclipse-uprotocol:mainfrom
sachinkum0009:feat/pyo3-rs-bindings

Conversation

@sachinkum0009
Copy link
Copy Markdown

Introduce the up_rust_py package, providing Python bindings for uProtocol. Include necessary modules, documentation, and example scripts for usage. This addition enhances the project's functionality and usability.

Copy link
Copy Markdown
Contributor

@sophokles73 sophokles73 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have provided a few hints and proposals for improvement. My Python knowledge is very limited so I the review of the python code might not be as thorough as you would expect.

I do like the clear structuring and that you already thought about including proper documentation 👍

In general, the Eclipse license header is missing in all files. You may want to take a look a the up-rust repository for the format of the header and where to add it.

Comment thread README.md
Comment thread pyproject.toml Outdated
requires-python = ">=3.8"
description = "Python bindings for Eclipse uProtocol Rust implementation"
readme = "README.md"
license = { text = "Apache-2.0" }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I see at https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license-and-license-files this should probably be

license = "Apache-2.0"

or am I mistaken?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, you're right. I will fix it.

Comment thread pyproject.toml
Comment thread pyproject.toml Outdated
Comment on lines +45 to +46
mqtt = [] # MQTT transport (future)
someip = [] # SOME/IP automotive protocol (future)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO we should omit these until there actually is support for them ...

Comment thread pyproject.toml Outdated
Comment on lines +49 to +52
discovery = [] # Service discovery (udiscovery feature)
subscription = [] # Advanced subscription management (usubscription feature)
twin = [] # Digital twin support (utwin feature)
cloudevents = [] # CloudEvents format support
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, FMPOV it is totally ok to only start with what is really supported. Once you add more bindings, e.g. for the uSubscription service interface, you can add a corresponding feature extension ..

Comment thread docs/installation.md Outdated

1. Clone the repository:
```bash
git clone https://github.com/sachinkum0009/up-rust-py.git
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this should become https://github.com/eclipse-uprotocol/up-rust-py.git, right?

Comment thread docs/installation.md
- Python 3.8 or higher
- pip (Python package installer)

## Install from PyPI
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO we should add a section recommending to use a virtual environment?

Comment thread docs/usage.md Outdated

Here's a simple example that demonstrates publishing and receiving messages:

```python
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of pasting the code in here (where we will have a hard time keeping it in sync with the code base), we should probably simply refer to a file in the examples folder?

Comment thread up_rust_py/__init__.pyi
entity ID, and version to create unique identifiers.
"""

def __init__(self, authority: str, entity_id: int, version: int) -> None:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if I provide a version value that is out of range?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found out that the PyO3 automatically converts Python types to Rust Types with validation.

If the value is out of range, it will return a OverflowError.

Comment thread up_rust_py/local_transport.pyi Outdated
Will be called when messages arrive.

Raises:
Exception: If registration fails.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not too familiar with error handling in Python but Exception looks very generic to me. Isn't there a concept for having more specific errors being reported?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I created a custom Expection class to handle and map the error from the rust e.g, UStatusError.

@sachinkum0009
Copy link
Copy Markdown
Author

sachinkum0009 commented Mar 4, 2026

To Do

  • small paragraph describing what this repo contains and what it is good for
  • update license text
  • omit libs until there actually is support for them
  • update repo link to new
  • update pytest to latest
  • update code to include binding which are currently implemented
  • tooling to generate docs from API
  • refer to files with examples
  • section to virtualenv
  • handle version value that is out of range
  • add exception handling to manage edge cases
  • add eclipse license header in all files

@sachinkum0009 sachinkum0009 marked this pull request as ready for review March 29, 2026 21:02
Comment thread README.md Outdated
- 🐍 **Pythonic API**: Easy-to-use interfaces that feel natural in Python
- ⚡ **Async Ready**: Built on Tokio async runtime for efficient I/O operations

## Installation (Comming Soon)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the package is not (yet) available from PyPi, then FMPOV we should not describe this as the (primary) way of installing the library, but add it once the package has been published for the first time. Otherwise, you will get questions why installation does not work as described ...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. I will update the Readme instructions.

Comment thread README.md
1. **Build from source using virtualenv**:

```bash
# activate virtualenv
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what this comment is supposed do mean. Do I need to manually activate virtualenv before, or does pip install maturing activate virtualenv?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, when using virtualenv. You have to manually activate virtualenv and then run the pip install command.

Comment thread README.md
- **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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds very expensive. Is this the recommended/established way to do this?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I will search for different way.

Comment thread test_zenoh_pubsub.py

# Wait a bit more for messages to be received
print("\n3. Waiting for message delivery...")
time.sleep(2)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO we should not sleep here but instead use some channel to signal that the receiver has actually received the message that had been sent.

Comment thread src/local_transport.rs
/// >>> text = message.extract_string()
/// >>> if text:
/// ... print(f"Received: {text}")
fn extract_string(&self) -> PyResult<Option<String>> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function seems to completely contradict the error handling logic from up_rust. Is this by intention? Unless there is a compelling reason to do so, I would propose to simply stick with the API provided by UMessage, e.g. extracting the payload as a byte array or deserializing ProtoBuf messages ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants