Simple JSON-RPC 2.0 client with no dependencies other than Python's standard library.
Project description
jrpc2
Simple JSON-RPC 2.0 client with no dependencies other than Python's standard library.
Requirements
Python 3.13+
Features
- Support for JSON-RPC 1.0 and 2.0 (default)
- HTTP transport
- Basic HTTP auth
- List params
- Named params
- Notifications
- Batch support
Install
pip install jrpc2
Usage
from jrpc2 import RpcClient
url = 'http://localhost:8332'
auth = ('user', 'password')
rpc = RpcClient(url, auth)
list_params = [1, 2]
named_params = {'a': 1, 'b': 2}
# Method calling with list or named params (one or the other, not both)
resp = rpc.call('testmethod') # no params
resp = rpc.call('testmethod2', 1, 2) # list params
resp = rpc.call('testmethod2', *list_params) # list params
resp = rpc.call('testmethod2', a=1, b=2) # named params
resp = rpc.call('testmethod2', **named_params) # named params
# Batch calling
resp = rpc.batch(['testmethod', 'testmethod2'], [[], [1, 2]])
resp = rpc.batch(['testmethod2', 'testmethod2'], [{'a': 5, 'b': 3}, {'a': 2, 'b': 1}])
resp = rpc.batch(['testmethod3', 'testmethod4']) # no params
# Notification
rpc.notify('testmethod5', 'test_data')
rpc.notify('testmethod5', test_data='test_data')
rpc.batch(['testmethod5', 'testmethod5'], [['test_data'], ['test_data2']], _notify=True)
The response is a dictionary of the JSON response object returned from the server (even on errors). An exception is raised if there is an error at the HTTP level when making the call/request.
The RPC 'id' is handled internally and incremented by 1 on each request.
RPC methods can also be called directly as attributes, provided that a method list is passed when creating the client:
rpc = RpcClient(url, auth, methods=['testmethod', 'testmethod2'])
resp = rpc.testmethod() # no params
resp = rpc.testmethod2(1, 2) # list params
resp = rpc.testmethod2(a=1, b=2) # named params
License
Copyright (C) 2026 by Joel Torres <joel@joeltorres.net>
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Project details
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 jrpc2-2026.2.21.tar.gz.
File metadata
- Download URL: jrpc2-2026.2.21.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5267c6e88a29ce0c9ac193364ed137ca9227e49032a288a215b4cd5a53172c42
|
|
| MD5 |
055365dc7109d5622d611438e2ed9e69
|
|
| BLAKE2b-256 |
38b45e56c9847d95ed1fe4b26c4e1b85fc7309f7fa507e906a3e0bd5abd8d66d
|
File details
Details for the file jrpc2-2026.2.21-py3-none-any.whl.
File metadata
- Download URL: jrpc2-2026.2.21-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
013bc85af3e6738e6bb63686275b5e1fdef67ad09b2844c4d936b53bcc50bf3b
|
|
| MD5 |
168880655e81d2e5f0c4fda2dbf72978
|
|
| BLAKE2b-256 |
8ae8ad2eee997bdec5180c78e5cb95d197b02bbdb7b338f5367ecae85cd1609d
|