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:

pip install rpc-cli

Or with Poetry

poetry add rpc-cli

Example

Given the following in a file demo.py.

from openrpc import RPCServer
from pydantic import BaseModel

from rpc_cli import cli

rpc = RPCServer()


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:
    """Summ all numbers in a list."""
    return sum(numbers)


if __name__ == "__main__":
    cli(rpc).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-2.2.3.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

rpc_cli-2.2.3-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rpc_cli-2.2.3.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.10.3-200.fc40.x86_64

File hashes

Hashes for rpc_cli-2.2.3.tar.gz
Algorithm Hash digest
SHA256 371af59b9c76cc5eb5d1286692f8f9917dcb4a272d01426d1da5b23a7e4a8ea8
MD5 44c724149f77f9a1eaadf06aec7bf35a
BLAKE2b-256 7f5abe2e1c84e7163f3fb7167a096c74d222251e217ce8825dfdd5bdfc2d2e35

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rpc_cli-2.2.3-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.10.3-200.fc40.x86_64

File hashes

Hashes for rpc_cli-2.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5feb6d971c8c5c41c2786a56a857f5275fb396162c508d91d6f4a8637b53b710
MD5 b43a549d1a1ded3358d717b44b75f1db
BLAKE2b-256 bde726d96afeda027d84faf2471a7ec2a4454829d886b72e9d8e8d7f286a4dd6

See more details on using hashes here.

Supported by

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