Skip to main content

Stateful rpc for Python

Project description

PyPI version License Python Versions test suite Coverage Status

An asyncio compatible RPC framework for building distributed applications.

RMY provides a high level API allowing to expose objects from one process to the other. It frees programmers from having to handle communication between processes while still providing enough control when needed. The simplest possible use of RMY framework looks as follows.

import rmy

class Demo:
    async def greet(self, name):
        return f"Hello {name}!"


if __name__ == "__main__":
    rmy.run_tcp_server(8080, Demo())

This will expose an instance of the Demo object which can then be remotely accessed to as follows.

import rmy
from hello_rmy_server import Demo

if __name__ == "__main__":
    with rmy.create_sync_client("localhost", 8080) as client:
        demo_remote = client.fetch_remote_object(Demo)
        while True:
            print('Enter your name:')
            name = input()
            print(demo_remote.greet.eval(name))

One can easily also asynchronously iterate through results generated by another object remotely. MY provides robust ways to iterate over (asynchronous) iterators applying back pressure if required. This allows to implement trivially Pub-Sub or any other event notification pattern easily. A trivial example of remote generator iteration might look like this.

import random

class Demo:
    ...
    async def count(self):
        for i in range(1_000_000):
            await asyncio.sleep(random.uniform())
            yield i

One can remotely iterate through the values using a normal loop.

for i in demo_remote.count():
    print(i)

For smplicity sake we showcased examples in synchronous code. One can easily make those asynchronous by instanciating an asynchronous client.

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

rmy-0.1.5.tar.gz (15.0 kB view hashes)

Uploaded Source

Built Distribution

rmy-0.1.5-py3-none-any.whl (16.4 kB 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