Skip to main content

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://user:pass@localhost:8332' # omit user:pass if there is no auth
rpc = RpcClient(url)

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, methods=['testmethod', 'testmethod2'])

resp = rpc.testmethod() # no params
resp = rpc.testmethod2(1, 2) # list params
resp = rpc.testmethod2(a=1, b=2) # named params

CLI

A CLI script (rpc-cli) is included for quick tests.

rpc-cli [-h] [-v] url method [params ...]
rpc-cli http://user:pass@localhost:8332 testmethod
rpc-cli http://user:pass@localhost:8332 testmethod2 1 2
rpc-cli http://user:pass@localhost:8332 testmethod2 a=1 b=2

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

jrpc2-2026.3.3.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jrpc2-2026.3.3-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file jrpc2-2026.3.3.tar.gz.

File metadata

  • Download URL: jrpc2-2026.3.3.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for jrpc2-2026.3.3.tar.gz
Algorithm Hash digest
SHA256 76a2a33a400a41f2ced735d5e80ca4cbebbd5935f17b79756c2ae676c4cde9a1
MD5 d2ad9a5ceb00a246ad0ab390df736d71
BLAKE2b-256 d61b86a2cc77410ad8985ad070ecdcc7d38a2a6233a5ca9971eb4be24a86e0f1

See more details on using hashes here.

File details

Details for the file jrpc2-2026.3.3-py3-none-any.whl.

File metadata

  • Download URL: jrpc2-2026.3.3-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for jrpc2-2026.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6384dcec370be3d55da44fdb0da0c46d8a59614cbd12d30d6722bc5d8569da5c
MD5 951eb6a4054196b41b4f5b1c7c46a832
BLAKE2b-256 6e0ccc9f256d6111d2f62b713d91d4bd8cea4ad97c0ed98b322eab576fcdc869

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page