Metadata-Version: 2.4
Name: pysonrpc
Version: 1.0.9
Summary: JSON RPC Python client with autodiscovery and methods mapping
Author-email: Vivien Chene <viv@vivc.org>
Maintainer-email: Vivien Chene <viv@vivc.org>
License: MIT License
        Copyright (c) <year> <copyright holders>
        
        Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
        
Project-URL: Homepage, https://github.com/vche/pysonrpc
Project-URL: Bug Reports, https://github.com/vche/pysonrpc/issues
Project-URL: Source, https://github.com/vche/pysonrpc
Keywords: python,json,rpc,setuptools
Classifier: Development Status :: 5 - Production/Stable
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3 :: Only
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests
Requires-Dist: prettytable
Provides-Extra: dev
Requires-Dist: pip; extra == "dev"
Requires-Dist: tox; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: codecov-cli; extra == "dev"
Provides-Extra: test
Requires-Dist: tox; extra == "test"
Dynamic: license-file

![GitHub](https://img.shields.io/github/license/vche/pysonrpc) [![Codecov](https://img.shields.io/codecov/c/github/vche/pysonrpc)](https://codecov.io/gh/vche/pysonrpc) [![GitHub release (latest by date)](https://img.shields.io/github/v/release/vche/pysonrpc)](https://github.com/vche/pysonrpc/releases) [![PyPI](https://img.shields.io/pypi/v/pysonrpc)](https://pypi.org/project/pysonrpc/) [![Downloads](https://pepy.tech/badge/pysonrpc)](https://pepy.tech/project/pysonrpc)

## What's pysonrpc

JSON RPC python client module with a CLI and method auto detection.

For JSON RPC server with a schema, an url canbe specified so that the schema is read, detecting the list of methods
supported.
Attributes are dynamically created to allow methods to be called as attributes, including namespaces.

Examples with [kodi](https://kodi.tv/) json rpc client:

### CLI

```bash
# List all methods available, autodetected from the server url (for kodi, this is not a complete list)
pysonrpc -r http://127.0.0.1:8080/jsonrpc -a list

# List all methods available, autodetected from a server rpc method
pysonrpc -r http://127.0.0.1:8080/jsonrpc -am "JSONRPC.Introspect" list -s -f VideoLibrary.

# List all methods available, autodetected from a schema json file
pysonrpc -r http://127.0.0.1:8080/jsonrpc -f schema.json list

# List methods filtered with VideoLibrary
pysonrpc -r http://127.0.0.1:8080/jsonrpc -am "JSONRPC.Introspect" list -s -f VideoLibrary

# Get favaourites list
pysonrpc -r http://127.0.0.1:8080/jsonrpc -a run -m Favourites.GetFavourites

# Get information on movie 1419
pysonrpc -r http://127.0.0.1:8080/jsonrpc -a run -m VideoLibrary.GetMovieDetails -p '{"movieid": 1419}'
```

Help
```bash
 usage: pysonrpc [-h] [--version] --url URL [--user USER] [--password PASSWORD] [--debug] [--method-discover] [--method-discover-path METHOD_DISCOVER_PATH]
                [--method-file METHOD_FILE]
                {list,run} ...

RPC client

positional arguments:
  {list,run}            commands
    list                List available methods
    run                 Execute a method

options:
  -h, --help            show this help message and exit
  --version, -v         Display version
  --url URL, -r URL     Host url, e.g 'http://192.168.0.1:8080'
  --user USER, -u USER  username if using basic authentication
  --password PASSWORD, -p PASSWORD
                        Password if using basic authentication
  --debug, -d           Enable debug logging
  --method-discover, -a
                        Auto discover rpc methods at the specified endpoint url
  --method-discover-path METHOD_DISCOVER_PATH
                        Specifies a path after the specified endpoint url to query for methods auto discovery
  --method-file METHOD_FILE, -f METHOD_FILE
                        Discover methods from given json file
```

### Python module

```python
from pysonrpc import JsonRpcEndpoint

cli = JsonRpcEndpoint("http://127.0.0.1:8080/jsonrpc", user="user", password="pwd", schema_method="JSONRPC.Introspect")

#Running a method from name
result=cli.run_method("Favourites.GetFavourites")
result=cli.run_method("VideoLibrary.GetMovieDetails", movieid=1419)

#Running a method from attribute
result=cli.Favourites.GetFavourites()
result=cli.VideoLibrary.GetMovieDetails(movieid=1419)
```

## Development

Using [pixi](https://pixi.sh/)

```sh
# Install dependencies and pycliarr
pixi build

# Run the binary
pixi run pysonrpc

# Or start a term
pixi shell

# Run tests
pixi run test

```

### Run tests

```sh
pixi run tox
```

If mypy fails due to missing import stubs:
```sh
.tox/checkers/bin/mypy --install-types
```

### Release

To push to main and increment the current version:
```sh
pixi run release
```

To push to main and specify the new version current version:
```sh
pixi run release 1.2.3
```

_Note: A workflow is validating, building, releasing and publishing push requests and tagged commits_

### TODO:
- better way for parameters ? (add a list arg for a method only)
- add recursivity to accept several namespaces
