Metadata-Version: 2.1
Name: pysonrpc
Version: 1.0.0
Summary: RPC Python client for kodi
Home-page: https://github.com/vche/pysonrpc
Author: Vivien Chene
Author-email: viv@vivc.org
Keywords: python tool
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Development Status :: 5 - Production/Stable
Classifier: Topic :: Home Automation
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: requests
Requires-Dist: prettytable

## Usage

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
pysonrpc -r http://127.0.0.1:8080/jsonrpc -a list

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

# List information for a specific method
pysonrpc -r http://127.0.0.1:8080/jsonrpc -a list -m VideoLibrary.GetMovieDetails

# Get favaourites list
pysonrpc -r http://127.0.0.1:8080/jsonrpc -a run 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="password", auto_detect=True)

#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 pycliarr

# Or start a term
pixi shell

# Run tests
pixi run tests

#generate doc
pixi run doc
```

### Run tests

```sh
pixi run tox
```

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

### Generate documentation:

```sh
pip install sphinx sphinx_rtd_theme m2r2
./setup.py doc
```

In case new classes/modules are added, update the autodoc list:
```sh
rm  docs/sphinx_conf/source/*
sphinx-apidoc -f -o docs/sphinx_conf/source/ src/pycliarr --separate
```

### TODO:
- better way for parameters ? (add a list arg for a method only)
- tests and coverage

