Skip to main content

Expose methods of an RPC server through a CLI.

Project description

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.

Demo

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

Buy Me A Coffee

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

rpc_cli-3.0.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

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

rpc_cli-3.0.0-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file rpc_cli-3.0.0.tar.gz.

File metadata

  • Download URL: rpc_cli-3.0.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for rpc_cli-3.0.0.tar.gz
Algorithm Hash digest
SHA256 ab3386b78ec806dd717a36a492b142ecd2b333d80b7093a0458815d8cb469ce7
MD5 69386db1fcccce0af6b6202a1e6f6f1c
BLAKE2b-256 b5f44f83cc34bfab88954d92281b842a091490a75428d8fe4b4b5029cc9f426e

See more details on using hashes here.

File details

Details for the file rpc_cli-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: rpc_cli-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for rpc_cli-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 46c91149e5456a29e988e25976ca703c2bc3a40b71ef62023b60bb5130727142
MD5 f93dd409de219942e2f11caafa987ab7
BLAKE2b-256 78d960dc4d1cbabd2bc2824e2bf7a9cf46f3a724acee54847b4a2ab5602ef9e7

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