No project description provided
Project description
Pickle RPC in Python
Very simple RPCs built with sockets & pickle in python. Support numpy as input and output arguments.
Install
pip install picklerpc
Example
Server
import picklerpc
import numpy as np
# function
def numpy_create(shape, dtype):
return np.arange(np.prod(shape), dtype=dtype).reshape(shape)
def hello():
return "Hello, world!"
def hello2():
return None
def add(a, b):
return a+b
class HelloRPC(object):
def hello3(self, name):
return "Hello, %s" % name
# register
server = picklerpc.PickleRPCServer(('localhost', 9102))
server.register_function(numpy_create)
server.register_function(hello)
server.register_function(hello2)
server.register_function(lambda x,y: x-y, 'minus')
server.register_function(add)
server.register_instance(HelloRPC()) #from instance
server.serve_forever()
Client
import picklerpc
import numpy as np
client = picklerpc.PickleRPCClient(('localhost', 9102))
print(client.numpy_create((3,4), dtype=np.float32))
print(client.hello())
print(client.hello3('From Instance'))
print(client.add(np.range(10), 3))
print(client.minus(np.range(10), 3))
Speed compare
The picklerpc is most 10x faster than zerorpc
and xmlrpc
.
zerorpc | xmlrpc | picklerpc (mine) | |
---|---|---|---|
Protocal | tcp | http | tcp |
Data Stream | - | xml | pickle |
Multiple Client | Yes | Yes | Yes |
Data Types | Natives | Natives | Natives + Numpy |
Speed (local loop) | 683 µs | 462 µs | 59 µs |
Speed (remote) | 2.76 ms | 4.64 ms | 0.54 ms |
Reference
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
picklerpc-0.1.0.tar.gz
(3.2 kB
view details)
File details
Details for the file picklerpc-0.1.0.tar.gz
.
File metadata
- Download URL: picklerpc-0.1.0.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b61147b177d2a6e9ff2cfb0cfa5cd2aa185bc9905d60ff91e5f2c96cfe574d48 |
|
MD5 | 7fd86340b5012722bbe46616347e2065 |
|
BLAKE2b-256 | 68eb675d7660e38ca606c81f6433e9982d73a2b8a612d2dc35ed589c7f9ac118 |