Yet-Another Light Weight RPC Framework Written in & for Python3.
- Easy-to-Use
- Dependency Free: No third-party dependencies are required.
- Transparent: Almost the same as calling local procedures.
- Thread Safe: Feel free to use the same Client object in different thread simultaneously.
- Polling Free: Block the thread before getting the result from the server instead of exhaustedly polling the status.
Server:
# import Listenerfromrpc.listenerimportListener# define your own proceduresdefsum(a, b):
returna+bdefupper(string):
returnstr.upper(string)
deflower(string):
returnstr.lower(string)
# instantiate a Listener objectlistener=Listener(ip, port, backlog)
# register your procedureslistener.register_procedure(sum)
listener.register_procedure(upper)
listener.register_procedure(lower)
# start serving, press `Ctrl+C` (maybe twice) to terminate the programlistener.listen()Client:
# import Clientfromrpc.clientimportClient# instantiate a Client objectclient=Client(ip, port)
# RPCclient.sum(1.0, 2.0)
client.upper("hello world!")
client.lower("HELLO WORLD!")
# Using keyword argumentsclient.sum(a=1.0, b=2.0)trying to call a non-registered procedure:
# trying to call a non-registered procedureclient.sin(3.14)
# outcomes Traceback (most recent call last): client.sin(3.14) AttributeError: 'Client' object has no attribute 'sin'
trying to pass illegal arguments to the call:
# trying to pass illegal arguments to the callclient.upper(1.0)
# outcomes Traceback (most recent call last): client.upper(1.0) File "YA-RPC\rpc\client.py", line 94, in func raise ret TypeError: descriptor 'upper' requires a 'str' object but received a 'float'
trying to pass mismatched number of arguments:
# trying to pass mismatched number of argumentsclient.sum(1.0)
# outcomes Traceback (most recent call last): client.sum(1.0) File "YA-RPC\rpc\client.py", line 94, in func raise ret TypeError: sum() missing 1 required positional argument: 'b'