RPC to CLI
Wrapper for Python OpenRPC to expose the methods of an RPC Server through a CLI.
Install
RPC CLI is on PyPI and can be installed with:
uv add rpc-cli
Or
pip install rpc-cli
Example
Given the following in a file demo.py.
from openrpc import RPCApp
from pydantic import BaseModel
from rpc_cli import cli
rpc = RPCApp()
class Vector3(BaseModel):
x: float
y: float
z: float
@rpc.method()
def get_distance(a: Vector3, b: Vector3) -> Vector3:
"""Get distance between two points."""
return Vector3(x=a.x - b.x, y=a.y - b.y, z=a.z - b.z)
@rpc.method()
def divide(a: int, b: int) -> float:
"""Divide two integers."""
return a / b
@rpc.method()
def summation(numbers: list[int | float]) -> int | float:
"""Sum all numbers in a list."""
return sum(numbers)
if __name__ == "__main__":
cli(rpc, exclude_discover=True).run()
You now have a CLI.
Using the CLI
Methods can be called as such, notice arrays and object parameters are passed as JSON strings.
python demo.py get_distance '{"x": 1, "y": 1, "z": 1}' '{"x": 1, "y": 1, "z": 1}'
python demo.py divide 6 2
python demo.py summation '[1, 2, 3]'
Auto Completions
This library uses cleo, auto completions can be made by following the instructions in the cleo docs.
Support The Developer
Metadata
Release files for rpc-cli 3.0.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 | |
|---|---|---|---|
| rpc_cli-3.0.0.tar.gz | 3.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| rpc_cli-3.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.7 kB
Release files / rpc_cli-3.0.0.tar.gz
| Download URL | rpc_cli-3.0.0.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ab3386b78ec806dd717a36a492b142ecd2b333d80b7093a0458815d8cb469ce7
|
|
BLAKE2b-256 checksum How to use checksums |
b5f44f83cc34bfab88954d92281b842a091490a75428d8fe4b4b5029cc9f426e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / rpc_cli-3.0.0-py3-none-any.whl
| Download URL | rpc_cli-3.0.0-py3-none-any.whl |
|---|---|
| Size | 4.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
46c91149e5456a29e988e25976ca703c2bc3a40b71ef62023b60bb5130727142
|
|
BLAKE2b-256 checksum How to use checksums |
78d960dc4d1cbabd2bc2824e2bf7a9cf46f3a724acee54847b4a2ab5602ef9e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|