Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wo1fsea/pyeasyrpc
a Python RPC framework using redis
https://github.com/wo1fsea/pyeasyrpc
python3 redis rpc-framework
Last synced: 21 days ago
JSON representation
a Python RPC framework using redis
- Host: GitHub
- URL: https://github.com/wo1fsea/pyeasyrpc
- Owner: wo1fsea
- License: mit
- Created: 2019-07-29T11:47:59.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-08-14T16:20:29.000Z (over 5 years ago)
- Last Synced: 2024-11-28T06:07:29.804Z (about 1 month ago)
- Topics: python3, redis, rpc-framework
- Language: Python
- Homepage:
- Size: 1.15 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PyEasyRPC
[![PyPI Status](https://badge.fury.io/py/pyeasyrpc.svg)](https://pypi.org/project/pyeasyrpc/)
[![Build Status](https://travis-ci.com/wo1fsea/PyEasyRPC.svg?branch=master)](https://travis-ci.com/wo1fsea/PyEasyRPC)
[![codecov](https://codecov.io/gh/wo1fsea/PyEasyRPC/branch/master/graph/badge.svg)](https://codecov.io/gh/wo1fsea/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 RPCServiceclass 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 RPCClientdef 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.pyimport asyncio
from pyeasyrpc.rpc import AsyncRPCClientdef 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()
```