Skip to main content

JSON RPC Python client with autodiscovery and methods mapping

Project description

GitHub Codecov GitHub release (latest by date) PyPI Downloads

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 json rpc client:

CLI

# 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

 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

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

# 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

pixi run tox

If mypy fails due to missing import stubs:

.tox/checkers/bin/mypy --install-types

Release

To push to main and increment the current version:

pixi run release

To push to main and specify the new version current version:

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)

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

pysonrpc-1.0.7.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

pysonrpc-1.0.7-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file pysonrpc-1.0.7.tar.gz.

File metadata

  • Download URL: pysonrpc-1.0.7.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for pysonrpc-1.0.7.tar.gz
Algorithm Hash digest
SHA256 63850f0633fdc26952774d8c7806d8bca41bf7d37491d08b14ce93c7e47746d0
MD5 a80d4caf765eae2d523780645d5f1005
BLAKE2b-256 e9f5203e64890a6733aab9bc7a9e59004af4a33a991e3b5454412d8ebd885efa

See more details on using hashes here.

File details

Details for the file pysonrpc-1.0.7-py3-none-any.whl.

File metadata

  • Download URL: pysonrpc-1.0.7-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for pysonrpc-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 33abbcf1191809b18d0f7d68e5d6670a7fd4b911473661db87e16b1e52ff17cc
MD5 64a7721c5c791e84388da8b832d63c0a
BLAKE2b-256 9f2f719425ada076c046f7d1b060e8d4a7bb9c6ef5619a33b0a41bdb17f93c5f

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