The fastrpc Python package provides funkcionality for easy creating both HTTP clients and servers using FastRPC or XML-RPC protocols.
The fastrpc Python package is compatible with the xmlrpclib (xmlrpc.client in Python 3) package. It's very simple to port project from xmlrpclib to fastrpc.
The binary fastrpc package needs to be installed first. See the installation instructions.
AUR package is available for Arch Linux distribution. The package can be installed using setuptools for other platforms:
git clone https://github.com/seznam/fastrpc.git
cd fastrpc/python
sudo python setup.py install
If you have gcc
version less than 6.0, you need to pass flag -std=c++11
:
CXXFLAGS='-std=c++11' CFLAGS='-std=c++11' CPPFLAGS='-std=c++11' sudo python setup.py install
ServerProxy
can be used very straightforwardly for client side code.
client = fastrpc.ServerProxy(url)
client.system.listMethods()
There are handlers for adding FastRPC endpoints to Flask, Aiohttp and Tornado web applications.
from fastrpc.handler.flask import FastRPCHandler
rpc = FastRPCHandler(flask_app, url='/RPC2')
rpc.register_method('add', add)
Server
can be also used to directly handle client sockets.
server = fastrpc.Server()
server.registry.register('add', add, 'S:s')
while True:
(clientsocket, address) = sock.accept()
server.serve(clientsocket, address)
For more specific needs, one can also use loads
and dumps
functions for converting the data between FastRPC/XML-RPC structures and Python objects and thus can create its own handler.
See Python examples for more.