rpc-cli


Namerpc-cli JSON
Version 2.2.3 PyPI version JSON
download
home_pagehttps://gitlab.com/mburkard/rpc-cli
SummaryExpose methods of an RPC server through a CLI.
upload_time2024-08-15 02:24:13
maintainerNone
docs_urlNone
authorMatthew Burkard
requires_python<4.0,>=3.10
licenseApache-2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # RPC to CLI

![](https://img.shields.io/badge/License-ApacheV2-blue.svg)
![](https://img.shields.io/badge/code%20style-black-000000.svg)
![](https://img.shields.io/pypi/v/rpc-cli.svg)

Wrapper for [Python OpenRPC](https://python-openrpc.burkard.cloud/) to expose the
methods of an RPC Server through a CLI.

## Install

RPC CLI is on PyPI and can be installed with:

```shell
pip install rpc-cli
```

Or with [Poetry](https://python-poetry.org/)

```shell
poetry add rpc-cli
```

## Example

Given the following in a file `demo.py`.

```python
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](https://gitlab.com/mburkard/rpc-cli/-/raw/main/docs/demo.png)

### Using the CLI

Methods can be called as such, notice arrays and object parameters are passed as JSON
strings.

```shell
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](https://github.com/python-poetry/cleo), auto completions can be
made by following the instructions in the
[cleo docs](https://cleo.readthedocs.io/en/latest/introduction.html#autocompletion).

## Support The Developer

<a href="https://www.buymeacoffee.com/mburkard" target="_blank">
  <img src="https://cdn.buymeacoffee.com/buttons/v2/default-blue.png"
       width="217"
       height="60"
       alt="Buy Me A Coffee">
</a>

            

Raw data

            {
    "_id": null,
    "home_page": "https://gitlab.com/mburkard/rpc-cli",
    "name": "rpc-cli",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": "Matthew Burkard",
    "author_email": "matthewjburkard@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/7f/5a/be2e1c84e7163f3fb7167a096c74d222251e217ce8825dfdd5bdfc2d2e35/rpc_cli-2.2.3.tar.gz",
    "platform": null,
    "description": "# RPC to CLI\n\n![](https://img.shields.io/badge/License-ApacheV2-blue.svg)\n![](https://img.shields.io/badge/code%20style-black-000000.svg)\n![](https://img.shields.io/pypi/v/rpc-cli.svg)\n\nWrapper for [Python OpenRPC](https://python-openrpc.burkard.cloud/) to expose the\nmethods of an RPC Server through a CLI.\n\n## Install\n\nRPC CLI is on PyPI and can be installed with:\n\n```shell\npip install rpc-cli\n```\n\nOr with [Poetry](https://python-poetry.org/)\n\n```shell\npoetry add rpc-cli\n```\n\n## Example\n\nGiven the following in a file `demo.py`.\n\n```python\nfrom openrpc import RPCServer\nfrom pydantic import BaseModel\n\nfrom rpc_cli import cli\n\nrpc = RPCServer()\n\n\nclass Vector3(BaseModel):\n    x: float\n    y: float\n    z: float\n\n\n@rpc.method()\ndef get_distance(a: Vector3, b: Vector3) -> Vector3:\n    \"\"\"Get distance between two points.\"\"\"\n    return Vector3(x=a.x - b.x, y=a.y - b.y, z=a.z - b.z)\n\n\n@rpc.method()\ndef divide(a: int, b: int) -> float:\n    \"\"\"Divide two integers.\"\"\"\n    return a / b\n\n\n@rpc.method()\ndef summation(numbers: list[int | float]) -> int | float:\n    \"\"\"Summ all numbers in a list.\"\"\"\n    return sum(numbers)\n\n\nif __name__ == \"__main__\":\n    cli(rpc).run()\n```\n\nYou now have a CLI.\n\n![Demo](https://gitlab.com/mburkard/rpc-cli/-/raw/main/docs/demo.png)\n\n### Using the CLI\n\nMethods can be called as such, notice arrays and object parameters are passed as JSON\nstrings.\n\n```shell\npython demo.py get_distance '{\"x\": 1, \"y\": 1, \"z\": 1}' '{\"x\": 1, \"y\": 1, \"z\": 1}'\npython demo.py divide 6 2\npython demo.py summation '[1, 2, 3]'\n```\n\n## Auto Completions\n\nThis library uses [cleo](https://github.com/python-poetry/cleo), auto completions can be\nmade by following the instructions in the\n[cleo docs](https://cleo.readthedocs.io/en/latest/introduction.html#autocompletion).\n\n## Support The Developer\n\n<a href=\"https://www.buymeacoffee.com/mburkard\" target=\"_blank\">\n  <img src=\"https://cdn.buymeacoffee.com/buttons/v2/default-blue.png\"\n       width=\"217\"\n       height=\"60\"\n       alt=\"Buy Me A Coffee\">\n</a>\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Expose methods of an RPC server through a CLI.",
    "version": "2.2.3",
    "project_urls": {
        "Homepage": "https://gitlab.com/mburkard/rpc-cli",
        "Repository": "https://gitlab.com/mburkard/rpc-cli"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bde726d96afeda027d84faf2471a7ec2a4454829d886b72e9d8e8d7f286a4dd6",
                "md5": "b43a549d1a1ded3358d717b44b75f1db",
                "sha256": "5feb6d971c8c5c41c2786a56a857f5275fb396162c508d91d6f4a8637b53b710"
            },
            "downloads": -1,
            "filename": "rpc_cli-2.2.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b43a549d1a1ded3358d717b44b75f1db",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 8093,
            "upload_time": "2024-08-15T02:24:11",
            "upload_time_iso_8601": "2024-08-15T02:24:11.437641Z",
            "url": "https://files.pythonhosted.org/packages/bd/e7/26d96afeda027d84faf2471a7ec2a4454829d886b72e9d8e8d7f286a4dd6/rpc_cli-2.2.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7f5abe2e1c84e7163f3fb7167a096c74d222251e217ce8825dfdd5bdfc2d2e35",
                "md5": "44c724149f77f9a1eaadf06aec7bf35a",
                "sha256": "371af59b9c76cc5eb5d1286692f8f9917dcb4a272d01426d1da5b23a7e4a8ea8"
            },
            "downloads": -1,
            "filename": "rpc_cli-2.2.3.tar.gz",
            "has_sig": false,
            "md5_digest": "44c724149f77f9a1eaadf06aec7bf35a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 7493,
            "upload_time": "2024-08-15T02:24:13",
            "upload_time_iso_8601": "2024-08-15T02:24:13.136780Z",
            "url": "https://files.pythonhosted.org/packages/7f/5a/be2e1c84e7163f3fb7167a096c74d222251e217ce8825dfdd5bdfc2d2e35/rpc_cli-2.2.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-15 02:24:13",
    "github": false,
    "gitlab": true,
    "bitbucket": false,
    "codeberg": false,
    "gitlab_user": "mburkard",
    "gitlab_project": "rpc-cli",
    "lcname": "rpc-cli"
}
        
Elapsed time: 0.34209s