Skip to main content

Wrapyfi is a wrapper for simplifying Middleware communication

Project description

Documentation Status

Wrapyfi is a middleware communication wrapper for transmitting data across nodes, without altering the operation pipeline of your Python scripts. Wrapyfi introduces a number of helper functions to make middleware integration possible without the need to learn an entire framework, just to parallelize your processes on multiple machines. Wrapyfi supports YARP, ROS, ROS2, and ZeroMQ.

To integrate Wrapyfi with your scripts, add the decorators describing the transmitting and listening method parameters.

Attribution

Please refer to the following paper when citing Wrapyfi in academic work:

@article{abawi2023wrapyfi,
  author = {Abawi, Fares and Allgeuer, Philipp and Fu, Di and Wermter, Stefan},
  title = {{Wrapyfi: A Wrapper for Message-Oriented and Robotics Middleware}},
  journal = {arXiv preprint arXiv:2302.09648},
  publisher = {arXiv},
  doi = {10.48550/ARXIV.2302.09648},
  url = {https://arxiv.org/abs/2302.09648},
  year = {2023}
}

Getting Started

Before using Wrapyfi, YARP, ROS, or ZeroMQ must be installed.

  • Follow the YARP installation guide. Note that the iCub package is not needed for Wrapyfi to work and does not have to be installed if you do not intend on using the iCub robot.

  • For installing ROS, follow the ROS installation guide. We recommend installing ROS on Conda using the RoboStack environment.

  • For installing ROS2, follow the ROS 2 installation guide. We recommend installing ROS 2 on Conda using the RoboStack environment.

  • ZeroMQ can be installed using pip: pip install pyzmq. The xpub-xsub pattern followed in our ZeroMQ implementation requires a proxy broker. A broker is spawned by default as a daemon process. To avoid automatic spawning, pass the argument start_proxy_broker=False to the method register decorator. A standalone broker can be found here

Compatibility

  • Ubuntu >= 18.04 (Not tested with earlier versions of Ubuntu or other OS)

  • Python >= 3.6

  • OpenCV >= 4.2

  • Numpy >= 1.19

  • YARP >= v3.3.2

  • ROS Noetic Ninjemys

  • ROS 2 Humble Hawksbill | Galactic Geochelone | Foxy Fitzroy

  • PyZMQ 16.0, 17.1 and 19.0

Installation

You can install Wrapyfi with pip or from source.

Pip

To install all the necessary components for the majority of common uses of Wrapyfi (e.g., NativeObject, Image, Audio, etc.) using pip, this process installs both Wrapyfi and its dependencies, like NumPy and OpenCV (opencv-contrib-python, opencv-headless, and opencv-python are supported), that are essential for various workloads, along with ZeroMQ being the default middleware. This option is the best for users running Wrapyfi out of the box in a newly created environment (without any middleware installed beforehand), installing numpy, opencv-contrib-python and pyzmq:

pip install wrapyfi[all]

Note that most plugins require additional dependencies and should be installed separately.

Other middleware such as ROS are environment-specific and require dependencies that cannot be installed using pip. Wrapyfi could and should be used within such environments with minimal requirements to avoid conflicts with existing NumPy and OpenCV packages:

pip install wrapyfi

Source

Clone the current repository:

git clone https://github.com/fabawi/wrapyfi.git
cd wrapyfi

You can choose to install minimal dependencies, for running a basic Wrapyfi script:

pip install .[all]

or install wrapyfi without NumPy, OpenCV, and ZeroMQ:

pip install .

Usage

Wrapyfi supports two patterns of communication:

  • Publisher-Subscriber (pub-sub): A publisher sends data to a subscriber accepting arguments and executing methods on the publisher's end. e.g., with YARP
Without Wrapyfi With Wrapyfi
# Just your usual Python class


class HelloWorld(object):
    
    
    
    
    def send_message(self):
        msg = input("Type your message: ")
        obj = {"message": msg}
        return obj,


hello_world = HelloWorld()



    

while True:
    my_message, = hello_world.send_message()
    print(my_message)
from wrapyfi.connect.wrapper import MiddlewareCommunicator


class HelloWorld(MiddlewareCommunicator):
    @MiddlewareCommunicator.register("NativeObject", "yarp",
                                     "HelloWorld", 
                                     "/hello/my_message", 
                                     carrier="", should_wait=True)
    def send_message(self):
        msg = input("Type your message: ")
        obj = {"message": msg}
        return obj,


hello_world = HelloWorld()

LISTEN = True
mode = "listen" if LISTEN else "publish"
hello_world.activate_communication(hello_world.send_message, mode=mode)

while True:
    my_message, = hello_world.send_message()
    print(my_message)

Run yarpserver from the command line. Now execute the Python script above (with Wrapyfi) twice setting LISTEN = False and LISTEN = True. You can now type with the publisher's command line and preview the message within the listener's

  • Request-Reply (req-rep): A requester sends a request to a responder, which responds to the request in a synchronous manner. e.g., with ROS
Without Wrapyfi With Wrapyfi
# Just your usual Python class


class HelloWorld(object):
    
    
    
    
    def send_message(self, a, b):
        msg = input("Type your message: ")
        obj = {"message": msg, 
               "a": a, "b": b, "sum": a + b}
        return obj,


hello_world = HelloWorld()



    

while True:
    my_message, = hello_world.send_message(a=1, 
                                           b=2)
    print(my_message)
from wrapyfi.connect.wrapper import MiddlewareCommunicator


class HelloWorld(MiddlewareCommunicator):
    @MiddlewareCommunicator.register("NativeObject", "ros",
                                     "HelloWorld", 
                                     "/hello/my_message", 
                                     carrier="", should_wait=True)
    def send_message(self, a, b):
        msg = input("Type your message: ")
        obj = {"message": msg, 
               "a": a, "b": b, "sum": a + b}
        return obj,


hello_world = HelloWorld()

LISTEN = True
mode = "request" if LISTEN else "reply"
hello_world.activate_communication(hello_world.send_message, mode=mode)

while True:
    my_message, = hello_world.send_message(a=1 if LISTEN else None, 
                                           b=2 if LISTEN else None)
    print(my_message)

Run roscore from the command line. Now execute the Python script above (with Wrapyfi) twice setting LISTEN = False and LISTEN = True. You can now type within the server's command line and preview the message within the client's. Note that the server's command line will not show the message until the client's command line has been used to send a request. The arguments are passed from the client to the server and the server's response is passed back to the client.

For more examples of usage, refer to the user guide. Run scripts in the examples directory for trying out Wrapyfi.

Supported Formats

Middleware

  • YARP
  • ROS
  • ROS2
  • ZeroMQ (beta feature: should_wait trigger introduced with event monitoring)

Serializers

  • JSON
  • msgpack
  • protobuf

Data Structures

Supported Objects by the NativeObject type include:

Image

Supported Objects by the Image type include:

Sound

Supported Objects by the AudioChunk type include:

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

wrapyfi-0.4.27.tar.gz (5.0 MB view hashes)

Uploaded Source

Built Distribution

wrapyfi-0.4.27-py3-none-any.whl (5.1 MB view hashes)

Uploaded Python 3

Supported by

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