a Python RPC framework using redis
Project description
PyEasyRPC
PyEaseRPC is a Python RPC framework easy to use, which using Redis as backend.
Example
Server
# example_server.py
from pyeasyrpc.rpc import remote_method
from pyeasyrpc.rpc import RPCService
class ServiceInstance(RPCService):
@remote_method
def add(self, a, b):
return a + b
@remote_method
def sub(self, a, b):
return a - b
@remote_method
def make_dict(self, **kwargs):
return dict(kwargs)
@remote_method
def make_list(self, *args):
return list(args)
def main():
instance0 = ServiceInstance(process_request_in_thread=True)
instance0.start_background_running()
input("press any key to stop")
instance0.stop_background_running()
if __name__ == '__main__':
main()
Client
# example_client.py
from pyeasyrpc.rpc import RPCClient
def main():
client = RPCClient("ServiceInstance")
print("method_list", client.get_methods())
print("add", client.add(1, 2))
print("sub", client.sub(100, 1.1))
print("make_dict", client.make_dict(a=1, b=2, c=3))
print("make_list", client.make_list(1, [2], {3}))
try:
client.add()
except Exception as ex:
print(type(ex), ex)
if __name__ == '__main__':
main()
Async Client
# example_client_async.py
import asyncio
from pyeasyrpc.rpc import AsyncRPCClient
def main():
client = AsyncRPCClient("ServiceInstance")
print("method_list", client.get_methods())
async def add():
print("add", await client.add(1, 2))
async def sub():
print("sub", await client.sub(100, 1.1))
async def make_dict():
print("make_dict", await client.make_dict(a=1, b=2, c=3))
async def make_list():
print("make_list", await client.make_list(1, [2], {3}))
async def catch_exception():
try:
await client.add()
except Exception as ex:
print(type(ex), ex)
async def func():
task = [add(), sub(), make_list(), make_dict(), catch_exception()]
# task.extend([add() for i in range(100)])
# task.extend([sub() for i in range(100)])
# task.extend([make_list() for i in range(100)])
# task.extend([make_dict() for i in range(100)])
# task.extend([catch_exception() for i in range(100)])
await asyncio.wait(task)
loop = asyncio.get_event_loop()
loop.run_until_complete(func())
if __name__ == '__main__':
main()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyeasyrpc-0.0.1.tar.gz
(15.0 kB
view details)
Built Distribution
pyeasyrpc-0.0.1-py3-none-any.whl
(23.9 kB
view details)
File details
Details for the file pyeasyrpc-0.0.1.tar.gz
.
File metadata
- Download URL: pyeasyrpc-0.0.1.tar.gz
- Upload date:
- Size: 15.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.6.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 107086074e1642b8b629596b0be4c382993b9c577f1c2e34086daaa04ef90349 |
|
MD5 | 6b2a3d4b7b39a89d48dad4598f7f7e05 |
|
BLAKE2b-256 | 443d2ba91e3c39040a3862c73542cca6a518898042947c5552948961125e578c |
File details
Details for the file pyeasyrpc-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: pyeasyrpc-0.0.1-py3-none-any.whl
- Upload date:
- Size: 23.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.6.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d6362a7c9b6c1fa4864d564d78ba4d93c2044417a24562e71c4168226c2dde6 |
|
MD5 | 528babefda8db70d236fe96b3dd44fe8 |
|
BLAKE2b-256 | 66959e4ab1fd646d340a14d4a69ba139be3458370633698e38893f42b1b8f90a |