/minirpc

A minimal and efficient RPC library for Python

Primary LanguagePythonGNU General Public License v2.0GPL-2.0

minirpc

A minimal and efficient JsonRPC library for Python.

The implementation is based on rpconnect. In this fork, I have made some improvements, such as similar usage like xmlrpc in Python standard libray (see usage below), and fixed many bugs.

Also, to make the behavior similar to xmlrpc, I have changed the running mode to calling functions directly, but not by forking a process or spawning a thread.

Dependency

Just standard library of Python.

Usage

server side

from minirpc import RpcServer

def _echo(info):
    return f'hello {info}'

server = RpcServer("localhost", 8800)
server.register_function(_echo, "echo")
server.serve_forever()

or

with RpcServer("localhost", 8800) as server:
    server.register(_echo, "echo")
    server.run()

client side

from minirpc import RpcClient

client = RpcClient("localhost", 8800)

msg = client.echo('world!')
print(msg)
# 'hello world!'