davidchern / minirpc

A minimal and efficient RPC library for Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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!'

About

A minimal and efficient RPC library for Python

License:GNU General Public License v2.0


Languages

Language:Python 100.0%