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 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))
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file socket_rpc-0.4.6.tar.gz.
File metadata
- Download URL: socket_rpc-0.4.6.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02e3c0501dc81976758e47723b347f22c576ab5ebc5d18b3982c06da32ceba73
|
|
| MD5 |
873b4edae67169f6b73a44f7cb77ef65
|
|
| BLAKE2b-256 |
354aba92fe94c32ba21dc5def5572d46377bbeca2799078993c346b96721ddcd
|
File details
Details for the file socket_rpc-0.4.6-py3-none-any.whl.
File metadata
- Download URL: socket_rpc-0.4.6-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a0ec6f949d5c82f1f22ed011cc6aca7d2bc457373955cd7f27b8bea078ec596c
|
|
| MD5 |
d935cc2d7c5166da8f083c7ceb322d5f
|
|
| BLAKE2b-256 |
b7580074352275307a548784c112129c3cef2ce0dc2265ec59397aaf39f82aea
|