Microlib for socket RPC
Project description
socket_rpc
socket_rpc
is a very simple microlib for remote procedure calls (RPC) over sockets in Python.
It exposes two class:
RPCServer
- acts as a server for a Python RPCRPCClient
- allows you to call a function, registered on another host with therpc
decorator.
Install with:
pip install socket_rpc
It has no external dependencies and is less than 100 lines of code.
It doesn't fork the process and guarantees you that the calls to a server will be processed in the same order in which they were done.
Quick server example
To expose a function over TCP, just decorate it with the rpc
decorator:
import logging
import sys
import numpy as np
from socket_rpc import RPCServer
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
def callback0(np_arr: np.ndarray):
print('0', np_arr.shape)
def callback1(np_arr: np.ndarray):
print('1', np_arr.shape)
server = RPCServer(host='localhost', port=61000, buffer_size=1 * 1024 * 1024)
server.add_fn(callback0)
server.add_fn(callback1)
server.serve()
Quick call example
To call a function already exposed with the rpc
decorator, just use the rpc_call
function:
import numpy as np
from socket_rpc import RPCClient
client = RPCClient('127.0.0.1', 5555)
client.callback0(np.arange(100))
client.callback1(np.arange(10))
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
socket_rpc-0.4.0.tar.gz
(3.4 kB
view hashes)
Built Distribution
Close
Hashes for socket_rpc-0.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bce798752f7d1aaabe5c16fda70f6f6cdca5da00450e9b499f3a4a3446516d36 |
|
MD5 | 2c0ae16f3e8a36675d358ff2e303271d |
|
BLAKE2b-256 | 8a0d5f22d15ca9086cd1ff0ee39fdd95a26af45ef2c4e5bdb2422308f86f10fa |