JSON-RPC Python Client
Library for interacting with JSON-RPC servers. Implements the JSON-RPC 2.0 spec, as well as first-class support for the subscription streaming endpoints exposed by most blockchain RPC interfaces (e.g. Ethereum, Solana) for JSON-RPC websockets connections.
Features
- Websockets connection wrapper with full support for matching request IDs to responses and subscription updates to subscription IDs
- Classes for (de)serializing JSON-RPC spec compliant message types
Installation
$ pip install bx-jsonrpc-py
Websockets Streaming
Many blockchains use a subscription RPC endpoint with JSON-RPC notifications to provide real-time event streams of updates in the network. They usually look something like this:
// create subscription
>> {"id": 1, "method": "subscribe", "params": ["feedName"]}
<< {"jsonrpc":"2.0","id":1,"result":"subscriptionID"}
// incoming notifications
<< {"jsonrpc":"2.0","method":"subscribe","params":{"subscription":"subscriptionID","result":"data"}}}
<< {"jsonrpc":"2.0","method":"subscribe","params":{"subscription":"subscriptionID","result":"data}}}
// cancel subscription
>> {"id": 1, "method": "unsubscribe", "params": ["subscriptionID"]}
<< {"jsonrpc":"2.0","id":1,"result":true}
Some examples: go-ethereum, solana
The included jsonrpc.WsRpcConnection class fully implements this feature.
Usage
import jsonrpc
async with jsonrpc.WsRpcConnection("ws://...") as ws:
print(await ws.call("method", {"param": "value"}))
subscription_id = await ws.subscribe(
"feedname", {"option": "value"}
)
async for notification in ws.notifications_for_id(subscription_id):
print(notification)
See examples/client.py for a working sample.
Anticipated Future Work
- Reconnection support for websockets to reconnect and resubscribe to former feeds
Comments / Questions
Feel free to open up a Github issue to discuss enhancements or problems.
MIT License
Copyright (c) 2022 bloXroute Labs
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Metadata
Release files for bx-jsonrpc-py 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bx-jsonrpc-py-0.2.0.tar.gz | 9.6 kB | Without provenance | Details for bx-jsonrpc-py-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bx_jsonrpc_py-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for bx_jsonrpc_py-0.2.0-py3-none-any.whl |
Total release size: 23.5 kB
Release files / bx-jsonrpc-py-0.2.0.tar.gz
| Download URL | bx-jsonrpc-py-0.2.0.tar.gz |
|---|---|
| Size | 9.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7d5b4888ac2aee1d65cc85b787f1cfb6cd61c07d28b5699c25764337b18ba37f
|
|
BLAKE2b-256 checksum How to use checksums |
cd699963fd07838e9ed35df5222a6978e52c98c58c3fc8aad0e589d68397e007
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.5
|
Release files / bx_jsonrpc_py-0.2.0-py3-none-any.whl
| Download URL | bx_jsonrpc_py-0.2.0-py3-none-any.whl |
|---|---|
| Size | 13.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9db51d433ecb4248c681c137a58050b820c2360f3b47d84c262991a29873c6f5
|
|
BLAKE2b-256 checksum How to use checksums |
555c6069accc43bdac9319f8dc2383b44904f4cec420c7f4703f9c6943af2601
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.5
|
Security for bx-jsonrpc-py 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.