Stateful rpc for Python
Project description
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
Built Distribution
File details
Details for the file rmy-0.1.5.tar.gz
.
File metadata
- Download URL: rmy-0.1.5.tar.gz
- Upload date:
- Size: 15.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.2 Darwin/22.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0173d53a016dc8dcf3ddb2db18d1039544b34902a05ee1e9c132ea581c8462bb |
|
MD5 | a0c51211ae1d88a06c7954d2c6af3288 |
|
BLAKE2b-256 | e6b04feb7582b25aac04a81a6de1eaa4d15c4167295479c52d77e338667b7453 |
Provenance
File details
Details for the file rmy-0.1.5-py3-none-any.whl
.
File metadata
- Download URL: rmy-0.1.5-py3-none-any.whl
- Upload date:
- Size: 16.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.2 Darwin/22.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8faca6aefa566475210802e0bbb156f2e425c096956bde232dc4ef7352a73448 |
|
MD5 | 9d5fe03264ca437fc34520cc8f2cdd7a |
|
BLAKE2b-256 | a212c569c967a8fe1af4efe58358baade4a61e64e7ec9a5b0ee3e920ea045fce |