rosy 🌹
It's not ROS... but it is ROS-y!
rosy, inspired by ROS (Robot Operating System), provides simple and fast inter-process message passing for distributed Python processes, or "nodes".
rosy allows sending messages between nodes in two different ways:
- Topics: Unidirectional, "fire and forget" messages that are sent from a node to all nodes listening to that topic.
- Services: Bidirectional, request-response messages that allow a node to get a response from any node hosting the service.
Messages can contain any Python data that is serializable by pickle (default), json, or msgpack. Alternatively, you can even provide your own custom codec.
Nodes can...
- Run on a single machine, or be distributed across multiple machines on a local network.
- Automatically discover each other using the Zeroconf protocol.
- Automatically reconnect to each other if they lose connection.
rosy also has simple load balancing: if multiple nodes of the same name are listening to a topic, then messages will be sent to them in a round-robin fashion. (The load balancing strategy can be changed or disabled if desired.)
Show me the code!
Here are some simplified examples. See the linked files for the full code.
Example: Sending messages using Topics
import rosy
async def main():
async with await rosy.build_node(name="topic_sender") as node:
await node.send("some-topic", "hello", name="world")
import rosy
async def main():
async with await rosy.build_node(name="topic_listener") as node:
await node.listen("some-topic", callback)
await node.forever()
async def callback(topic, message, name=None):
print(f'Received "{message} {name}" on topic={topic}')
Terminal:
# Terminal 1
$ python -m rosy.demo.topic_listener
Listening...
# Terminal 2
$ python -m rosy.demo.topic_sender
# Terminal 1
Received "hello world" on topic=some-topic
Example: Calling Services
import rosy
async def main():
async with await rosy.build_node(name="service_caller") as node:
print("Calculating 2 * 2...")
result = await node.call("multiply", 2, 2)
print(f"Result: {result}")
rosy/demo/service_provider.py:
import rosy
async def main():
async with await rosy.build_node(name="service_provider") as node:
await node.add_service("multiply", multiply)
await node.forever()
async def multiply(service, a, b):
return a * b
Terminal:
# Terminal 1
$ python -m rosy.demo.service_provider
Started service...
# Terminal 2
$ python -m rosy.demo.service_caller
Calculating 2 * 2...
Result: 4
Installation
pip install rosy
Commands
These commands mirror the ros2 ROS commands. Use the --help flag on any command to see all options.
$ rosy
Display help for all commands.
$ rosy node list
List all nodes in the mesh, what topics they are listening to, and what services they are providing.
$ rosy topic {list,echo,send}
List all topics, echo messages from a topic, or send a message to a topic.
$ rosy service {list,call}
List all services, or call a service.
$ rosy launch [config]
Launch several nodes all at once. config defaults to launch.yaml. Check out the template launch.yaml for all options, or the demo launch.yaml for a runnable example.
$ rosy bag {record,play,info}
Tool for recording and playing back messages. The options are:
record <topics>: Record messages on the given topic(s) to a file. By default, a file namedrecord_<datetime>.bagwill be created in the current directory.play: Play back messages from a bag file, with the same timing between messages as when they were recorded. By default, the most recent bag file in the current directory will be played back.info: Print information about a bag file. By default, the most recent bag file in the current directory will be used.
$ rosy speedtest {send,recv}
Performs a speed test sending and receiving topic messages.
Some results:
| Hardware | Message size | Messages/s | Latency (ms) | Bandwidth (MB/s) |
|---|---|---|---|---|
| Laptop* | 0 | 116000 | 0.023 | N/A |
| Laptop* | 1 kB | 115000 | 0.028 | 115 |
| Laptop* | 1 MB | 1300 | 1.2 | 1300 |
| Orin Nano** | 0 | 29000 | 0.13 | N/A |
| Orin Nano** | 1 kB | 28000 | 0.15 | 28 |
| Orin Nano** | 1 MB | 363 | 3.6 | 363 |
* Dell XPS 17 9730 with an Intel Core i9-13900H CPU and 64 GB DDR5 RAM running Ubuntu 24.04 and Python 3.10.
** NVIDIA Jetson Orin Nano
running Ubuntu 22.04 and Python 3.13.
What is a mesh?
A mesh is a collection of "nodes" that can send messages to each other. A message can be any Python object. There is one node per Python process, with nodes potentially distributed across multiple machines. Each node listens to specific message "topics", and calls listener callbacks when messages are received on those topics. Each node can send messages to any topic, and the message will be sent to all listening nodes.
How does it work?
The nodes use the Zeroconf protocol to discover each other and share their supported connection specifications, topics they are listening to, and services they are providing. Each node maintains the current "mesh topology" of all other nodes in the mesh.
When a node needs to send a message, it uses the mesh topology to find all currently listening nodes, connects to them, and sends the message.
Domain IDs
Nodes will only form a mesh and communicate with other nodes sharing the same "domain ID". The default domain ID is "default".
If you want to have multiple, independent meshes on the same network (e.g. you have multiple robots), you can use a different domain ID for each mesh. Here are some examples:
await rosy.build_node(..., domain_id="my-domain")
# The rosy CLI has a dedicated argument
$ rosy --domain-id my-domain ...
# Or you can set the ROSY_DOMAIN_ID environment variable
$ ROSY_DOMAIN_ID=my-domain rosy ...
Guarantees
rosy only guarantees that topic messages and service requests will be received in the order in which they were sent from a single node. It is possible for messages sent from different nodes to be received out of order.
It does not guarantee topic message delivery; there are no delivery confirmations, and if a message fails to be sent to a node (e.g. due to network failure), it will not be retried.
Security
Security is not a primary concern of rosy. Messages are sent unencrypted for speed and simplicity, and there is no authentication of nodes on the mesh.
Metadata
Release files for rosy 0.8.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rosy-0.8.3.tar.gz | 37.9 kB | Without provenance | Details for rosy-0.8.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rosy-0.8.3-py3-none-any.whl | Python 3 | none | any | Details for rosy-0.8.3-py3-none-any.whl |
Total release size: 96.2 kB
Release files / rosy-0.8.3.tar.gz
| Download URL | rosy-0.8.3.tar.gz |
|---|---|
| Size | 37.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7ded5fda8796648a6a94a6ca2f1144de681e0ee6efe6db1ff3c2894e81f5c3f4
|
|
BLAKE2b-256 checksum How to use checksums |
2b3871f865880d504355d0977522736b59b8919742c21390d616e88440faa095
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.12.3 Linux/6.14.0-29-generic
|
Release files / rosy-0.8.3-py3-none-any.whl
| Download URL | rosy-0.8.3-py3-none-any.whl |
|---|---|
| Size | 58.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
41614b99e67773c6bfc62b2b375cd78881ac2e831342e55d6d902efa4b40d486
|
|
BLAKE2b-256 checksum How to use checksums |
a3ba52e09db202a2b3698a2dba3a092974549e0ab82cb5af8b2593c1bec6a570
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.12.3 Linux/6.14.0-29-generic
|
Security for rosy 0.8.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.