jsonrpyc


Namejsonrpyc JSON
Version 1.3.0 PyPI version JSON
download
home_pageNone
SummaryMinimal python RPC implementation in a single file based on the JSON-RPC 2.0 specs from http://www.jsonrpc.org/specification.
upload_time2024-04-14 11:47:00
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseCopyright (c) 2016-2024, Marcel Rieger All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
keywords rpc json json-rpc jsonrpc 2.0
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <!-- marker-before-logo -->

<p align="center">
  <img src="https://media.githubusercontent.com/media/riga/jsonrpyc/master/assets/logo.png" width="400" />
</p>

<!-- marker-after-logo -->

<!-- marker-before-badges -->

<p align="center">
  <a href="http://jsonrpyc.readthedocs.io">
    <img alt="Documentation status" src="https://readthedocs.org/projects/jsonrpyc/badge/?version=latest" />
  </a>
  <img alt="Python version" src="https://img.shields.io/badge/Python-%E2%89%A53.8-blue" />
  <a href="https://pypi.python.org/pypi/jsonrpyc">
    <img alt="Package version" src="https://img.shields.io/pypi/v/jsonrpyc.svg?style=flat" />
  </a>
  <a href="https://codecov.io/gh/riga/jsonrpyc">
    <img alt="Code coverge" src="https://codecov.io/gh/riga/jsonrpyc/branch/master/graph/badge.svg?token=R8SY3O6KB9" />
  </a>
  <a href="https://github.com/riga/jsonrpyc/actions/workflows/lint_and_test.yml">
    <img alt="Build status" src="https://github.com/riga/jsonrpyc/actions/workflows/lint_and_test.yml/badge.svg" />
  </a>
  <a href="https://github.com/riga/jsonrpyc/blob/master/LICENSE">
    <img alt="License" src="https://img.shields.io/github/license/riga/jsonrpyc.svg" />
  </a>
</p>

<!-- marker-after-badges -->

<!-- marker-before-header -->

Minimal python RPC implementation based on the [JSON-RPC 2.0 specs](http://www.jsonrpc.org/specification).

Original source hosted at [GitHub](https://github.com/riga/jsonrpyc).

<!-- marker-after-header -->

<!-- marker-before-body -->

<!-- marker-before-usage -->

## 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](https://github.com/riga/node-json-rpc).
A ``jsonrpyc.RPC`` instance may wrap a *target* object.
Incomming requests will be routed to methods of this object whose result might be sent back as a response. Example implementation:


### ``server.py``

```python
import jsonrpyc

class MyTarget(object):

    def greet(self: MyTarget, name: str) -> str:
        return f"Hi, {name}!"

jsonrpyc.RPC(MyTarget())
```


### ``client.py``

```python
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
#

p.stdin.close()
p.stdout.close()
p.terminate()
p.wait()
```

<!-- marker-after-usage -->

<!-- marker-before-info -->

## Installation

Install simply via [pip](https://pypi.python.org/pypi/jsonrpyc).

```bash
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.
Just make sure to add new test cases, run them via

```bash
> pytest tests
```

and check for linting and typing errors with

```bash
> mypy jsonrpyc
> flake8 jsonrpyc
```


## Development

- Source hosted at [GitHub](https://github.com/riga/jsonrpyc)
- Report issues, questions, feature requests on [GitHub Issues](https://github.com/riga/jsonrpyc/issues)

<!-- marker-after-info -->

<!-- marker-after-body -->

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "jsonrpyc",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "rpc, json, json-rpc, jsonrpc, 2.0",
    "author": null,
    "author_email": "Marcel Rieger <github.riga@icloud.com>",
    "download_url": "https://files.pythonhosted.org/packages/93/d4/0002983a7fe61329566e906559cde0798e9cb90f52e438faff91032024b8/jsonrpyc-1.3.0.tar.gz",
    "platform": null,
    "description": "<!-- marker-before-logo -->\n\n<p align=\"center\">\n  <img src=\"https://media.githubusercontent.com/media/riga/jsonrpyc/master/assets/logo.png\" width=\"400\" />\n</p>\n\n<!-- marker-after-logo -->\n\n<!-- marker-before-badges -->\n\n<p align=\"center\">\n  <a href=\"http://jsonrpyc.readthedocs.io\">\n    <img alt=\"Documentation status\" src=\"https://readthedocs.org/projects/jsonrpyc/badge/?version=latest\" />\n  </a>\n  <img alt=\"Python version\" src=\"https://img.shields.io/badge/Python-%E2%89%A53.8-blue\" />\n  <a href=\"https://pypi.python.org/pypi/jsonrpyc\">\n    <img alt=\"Package version\" src=\"https://img.shields.io/pypi/v/jsonrpyc.svg?style=flat\" />\n  </a>\n  <a href=\"https://codecov.io/gh/riga/jsonrpyc\">\n    <img alt=\"Code coverge\" src=\"https://codecov.io/gh/riga/jsonrpyc/branch/master/graph/badge.svg?token=R8SY3O6KB9\" />\n  </a>\n  <a href=\"https://github.com/riga/jsonrpyc/actions/workflows/lint_and_test.yml\">\n    <img alt=\"Build status\" src=\"https://github.com/riga/jsonrpyc/actions/workflows/lint_and_test.yml/badge.svg\" />\n  </a>\n  <a href=\"https://github.com/riga/jsonrpyc/blob/master/LICENSE\">\n    <img alt=\"License\" src=\"https://img.shields.io/github/license/riga/jsonrpyc.svg\" />\n  </a>\n</p>\n\n<!-- marker-after-badges -->\n\n<!-- marker-before-header -->\n\nMinimal python RPC implementation based on the [JSON-RPC 2.0 specs](http://www.jsonrpc.org/specification).\n\nOriginal source hosted at [GitHub](https://github.com/riga/jsonrpyc).\n\n<!-- marker-after-header -->\n\n<!-- marker-before-body -->\n\n<!-- marker-before-usage -->\n\n## Usage\n\n``jsonrpyc.RPC`` instances basically wrap an input stream and an output stream in order to communicate with other *services*.\nA service is not even forced to be written in Python as long as it strictly implements the JSON-RPC 2.0 specs.\nA suitable implementation for NodeJs is [node-json-rpc](https://github.com/riga/node-json-rpc).\nA ``jsonrpyc.RPC`` instance may wrap a *target* object.\nIncomming requests will be routed to methods of this object whose result might be sent back as a response. Example implementation:\n\n\n### ``server.py``\n\n```python\nimport jsonrpyc\n\nclass MyTarget(object):\n\n    def greet(self: MyTarget, name: str) -> str:\n        return f\"Hi, {name}!\"\n\njsonrpyc.RPC(MyTarget())\n```\n\n\n### ``client.py``\n\n```python\nimport jsonrpyc\nfrom subprocess import Popen, PIPE\n\np = Popen([\"python\", \"server.py\"], stdin=PIPE, stdout=PIPE)\nrpc = jsonrpyc.RPC(stdout=p.stdin, stdin=p.stdout)\n\n\n#\n# sync usage\n#\n\nprint(rpc(\"greet\", args=(\"John\",), block=0.1))\n# => \"Hi, John!\"\n\n\n#\n# async usage\n#\n\ndef cb(err: Exception | None, res: str | None = None) -> None:\n    if err:\n        raise err\n    print(f\"callback got: {res}\")\n\nrpc(\"greet\", args=(\"John\",), callback=cb)\n\n# cb is called asynchronously which prints\n# => \"callback got: Hi, John!\"\n\n\n#\n# shutdown\n#\n\np.stdin.close()\np.stdout.close()\np.terminate()\np.wait()\n```\n\n<!-- marker-after-usage -->\n\n<!-- marker-before-info -->\n\n## Installation\n\nInstall simply via [pip](https://pypi.python.org/pypi/jsonrpyc).\n\n```bash\npip install jsonrpyc\n\n# or with optional dev dependencies\npip install jsonrpyc[dev]\n```\n\n\n## Contributing\n\nIf you like to contribute to jsonrpyc, I'm happy to receive pull requests.\nJust make sure to add new test cases, run them via\n\n```bash\n> pytest tests\n```\n\nand check for linting and typing errors with\n\n```bash\n> mypy jsonrpyc\n> flake8 jsonrpyc\n```\n\n\n## Development\n\n- Source hosted at [GitHub](https://github.com/riga/jsonrpyc)\n- Report issues, questions, feature requests on [GitHub Issues](https://github.com/riga/jsonrpyc/issues)\n\n<!-- marker-after-info -->\n\n<!-- marker-after-body -->\n",
    "bugtrack_url": null,
    "license": "Copyright (c) 2016-2024, Marcel Rieger All rights reserved.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.  * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ",
    "summary": "Minimal python RPC implementation in a single file based on the JSON-RPC 2.0 specs from http://www.jsonrpc.org/specification.",
    "version": "1.3.0",
    "project_urls": {
        "Documentation": "https://jsonrpyc.readthedocs.io",
        "Homepage": "https://github.com/riga/jsonrpyc",
        "Repository": "https://github.com/riga/jsonrpyc.git"
    },
    "split_keywords": [
        "rpc",
        " json",
        " json-rpc",
        " jsonrpc",
        " 2.0"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5169a4bc7c4a203cc296701c7cce5e9ef3a6a70e2814795f7a5e122719b8f512",
                "md5": "8a3d20e0ecf60223362b530213c102c5",
                "sha256": "991cbbb44aa3aac7e19a9c6c6438919e970433fe1421f0250f2703527716bc53"
            },
            "downloads": -1,
            "filename": "jsonrpyc-1.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8a3d20e0ecf60223362b530213c102c5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 12209,
            "upload_time": "2024-04-14T11:46:59",
            "upload_time_iso_8601": "2024-04-14T11:46:59.050102Z",
            "url": "https://files.pythonhosted.org/packages/51/69/a4bc7c4a203cc296701c7cce5e9ef3a6a70e2814795f7a5e122719b8f512/jsonrpyc-1.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "93d40002983a7fe61329566e906559cde0798e9cb90f52e438faff91032024b8",
                "md5": "494889865345dfc6076d6a21ff5da762",
                "sha256": "f55cdae31d2153b3d2bb82db409c794859e87bd4f6fe4e2723d2ebad4418c053"
            },
            "downloads": -1,
            "filename": "jsonrpyc-1.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "494889865345dfc6076d6a21ff5da762",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 14672,
            "upload_time": "2024-04-14T11:47:00",
            "upload_time_iso_8601": "2024-04-14T11:47:00.857575Z",
            "url": "https://files.pythonhosted.org/packages/93/d4/0002983a7fe61329566e906559cde0798e9cb90f52e438faff91032024b8/jsonrpyc-1.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-14 11:47:00",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "riga",
    "github_project": "jsonrpyc",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "jsonrpyc"
}
        
Elapsed time: 0.41665s