Simple JSON-RPC service without transport layer
Project description
JSONRPCBase
NOTE: This is a fork of level12/jsonrpcbase with changes maintained by KBase
Simple JSON-RPC service without transport layer
This library is intended as an auxiliary library for easy an implementation of JSON-RPC services with Unix/TCP socket like transport protocols that do not have complex special requirements. You need to utilize some suitable transport protocol with this library to actually provide a working JSON-RPC service.
Features
- Easy to use, small size, well tested.
- Supports JSON-RPC v2.0. Compatible with v1.x style calls with the exception of v1.0 class-hinting.
- Optional argument type validation that significantly eases development of jsonrpc method_data.
Example
Example usage:
import jsonrpcbase
chat_service = jsonrpcbase.JSONRPCService()
def login(username, password, timelimit=0):
# (...)
return True
def receive_message(**kwargs):
# (...)
return chat_message
def send_message(msg):
# (...)
pass
if __name__ == '__main__':
# Adds the method login to the service as a 'login'.
chat_service.add(login, types=[basestring, basestring, int])
# Adds the method receive_message to the service as a 'recv_msg'.
chat_service.add(receive_message, name='recv_msg', types={"msg": basestring, "id": int})
# Adds the method send_message as a 'send_msg' to the service.
chat_service.add(send_message, 'send_msg')
# Receive a JSON-RPC call.
jsonmsg = my_socket.recv()
# Process the JSON-RPC call.
result = chat_service.call(jsonmsg)
# Send back results.
my_socket.send(result)
Development
Install poetry and run poetry install
.
Run tests with make test
.
Deploy with poetry build
and poetry publish
.
Credits
This project was originally developed by Juhani Åhman.
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
Hashes for kbase_jsonrpcbase-0.3.0a4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60d2abd25ea129d301b6ae59904e385ae0c7f3eebcee444ac0c7f1ab73435ca0 |
|
MD5 | d3f260c2ec0dcb4588c162a10144bc99 |
|
BLAKE2b-256 | f7dcc78e98c3f6bdefab1f2eb3e105c6e9cc7aa0973c246e6e2aac92afb07361 |
Hashes for kbase_jsonrpcbase-0.3.0a4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 192b355f5a665524ebba55bd23e4c78d2adc9e8045eeb89f0cefd956c30900eb |
|
MD5 | 3329ec4a96bfb1d4bb94c60967783ab6 |
|
BLAKE2b-256 | a7eb16db3dcd53e1cbcc226b2e7ae56911e08e0889575f270aa13cd96fc378be |