Minimal python RPC implementation based on the JSON-RPC 2.0 specs.
Original source hosted at GitHub.
Usage
jsonrpyc.RPC instances basically wrap an input stream and an output stream in order to communicate with other services.
A service is not even forced to be written in Python as long as it strictly implements the JSON-RPC 2.0 specs.
A suitable implementation for NodeJs is node-json-rpc.
Request parameters can be passed as a plain list (positional arguments) or object (keyword arguments), or in the {"args": [...], "kwargs": {...}} format used by jsonrpyc itself.
A jsonrpyc.RPC instance may wrap a target object.
Incoming requests will be routed to methods of this object whose result might be sent back as a response.
Nested attributes can be addressed via dots (e.g. "sub.method"), while attributes starting with two underscores are not accessible.
Example implementation:
server.py
import jsonrpyc
class MyTarget:
def greet(self, name: str) -> str:
return f"Hi, {name}!"
jsonrpyc.RPC(MyTarget())
client.py
import jsonrpyc
from subprocess import Popen, PIPE
p = Popen(["python", "server.py"], stdin=PIPE, stdout=PIPE)
rpc = jsonrpyc.RPC(stdout=p.stdin, stdin=p.stdout)
#
# sync usage
#
print(rpc("greet", args=("John",), block=0.1))
# => "Hi, John!"
#
# async usage
#
def cb(err: Exception | None, res: str | None = None) -> None:
if err:
raise err
print(f"callback got: {res}")
rpc("greet", args=("John",), callback=cb)
# cb is called asynchronously which prints
# => "callback got: Hi, John!"
#
# shutdown
#
rpc.close()
p.stdin.close()
p.stdout.close()
p.terminate()
p.wait()
Installation
Install simply via pip.
pip install jsonrpyc
# or with optional dev dependencies
pip install jsonrpyc[dev]
Contributing
If you like to contribute to jsonrpyc, I'm happy to receive pull requests.
The full testing pipeline is based on pre-commit. Run the following to install development dependencies and set it up:
# inside the cloned repository
git lfs install
pip install -e .[dev]
pre-commit install
Now, every time you make a commit, the pre-commit and pre-push hooks will automatically run linting, type checking and unit tests. To run them manually, use
# for linting, type checking and additional checks on all files
pre-commit run --all-files
# only for staged files
pre-commit run
# or run unit tests standalone
pytest
Development
- Source hosted at GitHub
- Report issues, questions, feature requests on GitHub Issues
Metadata
Release files for jsonrpyc 1.4.1
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 |
|---|---|---|---|---|
| jsonrpyc-1.4.1.tar.gz | 13.8 kB | Without provenance | Details for jsonrpyc-1.4.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| jsonrpyc-1.4.1-py3-none-any.whl | Python 3 | none | any | Details for jsonrpyc-1.4.1-py3-none-any.whl |
Total release size: 27.3 kB
Release files / jsonrpyc-1.4.1.tar.gz
| Download URL | jsonrpyc-1.4.1.tar.gz |
|---|---|
| Size | 13.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f4c6cfa864c5a39211eb5b7be1e49916491e66a4aec8bd3318973e3a4fd1347e
|
|
BLAKE2b-256 checksum How to use checksums |
b6fcbef740dc5df31e20b2c780a9414fb0f7b52d16ffc91ae57de2d4e8e46419
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / jsonrpyc-1.4.1-py3-none-any.whl
| Download URL | jsonrpyc-1.4.1-py3-none-any.whl |
|---|---|
| Size | 13.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3b80e708da907ce5f8866c41e6817fac0671924fcc48bde895ec82c6d20e2320
|
|
BLAKE2b-256 checksum How to use checksums |
5be28bd055bcd36582d8c55f31d3cb707d05b6f64e1e154c9f76500dac1c66ff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for jsonrpyc 1.4.1
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.