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 pysonrpc

# Or start a term
pixi shell

# Run tests
pixi run test

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)
  • add recursivity to accept several namespaces

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.9.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pysonrpc-1.0.9-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pysonrpc-1.0.9.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pysonrpc-1.0.9.tar.gz
Algorithm Hash digest
SHA256 cf0f706ef2007af7f4947b78d7662477705e3bf58b9fc07443337c1b82a645ea
MD5 b734ed228794d91a97c3f252bcc80b21
BLAKE2b-256 7ce86d67dd72765c0fcebec437643db32952a802082e9841762f1a3b160619ec

See more details on using hashes here.

Provenance

The following attestation bundles were made for pysonrpc-1.0.9.tar.gz:

Publisher: build-release.yml on vche/pysonrpc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: pysonrpc-1.0.9-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pysonrpc-1.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 83be78cb7b2416dd83a6a1c9bf4548f52736ac3c19c6931f0bc13eed51d9cd71
MD5 4bdb99102dc796a746c12152c83f004a
BLAKE2b-256 6e4d8b96e100b4d8cdd7c60c6da4c0a65efc9144d776d557c3e0ec8ebd7d96bb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pysonrpc-1.0.9-py3-none-any.whl:

Publisher: build-release.yml on vche/pysonrpc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page