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 therpcdecorator.
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))
Release files for socket-rpc 0.4.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| socket_rpc-0.4.6.tar.gz | 3.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| socket_rpc-0.4.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.6 kB
Release files / socket_rpc-0.4.6.tar.gz
| Download URL | socket_rpc-0.4.6.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
02e3c0501dc81976758e47723b347f22c576ab5ebc5d18b3982c06da32ceba73
|
|
BLAKE2b-256 checksum How to use checksums |
354aba92fe94c32ba21dc5def5572d46377bbeca2799078993c346b96721ddcd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.8
|
Release files / socket_rpc-0.4.6-py3-none-any.whl
| Download URL | socket_rpc-0.4.6-py3-none-any.whl |
|---|---|
| Size | 4.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a0ec6f949d5c82f1f22ed011cc6aca7d2bc457373955cd7f27b8bea078ec596c
|
|
BLAKE2b-256 checksum How to use checksums |
b7580074352275307a548784c112129c3cef2ce0dc2265ec59397aaf39f82aea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.8
|