slxjsonrpc 0.9.2
SlxJsonRpc JsonRpc helper class, that uses pydantic.
License: Apache-2.0
Requires Python: >=3.7.0

slxjsonrpc
===============================================================================
[![versions](https://img.shields.io/pypi/pyversions/slxjsonrpc.svg)](https://github.com/wappsto/slxjsonrpc)
[![Test Status](https://github.com/Wappsto/slxjsonrpc/actions/workflows/test.yml/badge.svg)](https://github.com/Wappsto/slxjsonrpc/actions/workflows/test.yml)
[![Lint Status](https://github.com/Wappsto/slxjsonrpc/actions/workflows/lint.yml/badge.svg)](https://github.com/Wappsto/slxjsonrpc/actions/workflows/lint.yml)
[![Coverage](https://codecov.io/github/wappsto/slxjsonrpc/branch/main/graph/badge.svg)](https://codecov.io/github/wappsto/slxjsonrpc)
[![pypi](https://img.shields.io/pypi/v/slxjsonrpc.svg)](https://pypi.python.org/pypi/slxjsonrpc)
[![license](https://img.shields.io/github/license/wappsto/slxjsonrpc.svg)](https://github.com/wappsto/slxjsonrpc/blob/main/LICENSE)
[![SeluxitA/S](https://img.shields.io/badge/Seluxit_A/S-1f324d.svg?logo=data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAAFUAAABVCAYAAAA49ahaAAAACXBIWXMAABOvAAATrwFj5o7DAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAACjNJREFUeJztnX+wVVUVxz9cHr8fj5EfFipYU/AktBkyB6icgn4gMk5/NE0/SU1Ek6k0tAisrIQkkHKG6AeYFSmafzU2088BE0RiypHIDJlS0IGJhygC7/Hg8b79se7lnXveOveee88597776Duz583b5+y91/nec87ae6211xkgiT6AEcBlwCVAKzAZmAiMyh9rBlqA14HjwAngKLAf2AM8D/wL2J0/VlcMqBOpg4F3AbOBWcB0YFAK/Z4CdgKb8+WpfF1NUWtSLwc+A3wCGFeD8V4DfgVsBJ4EanKxtSB1OLAAWIQ91vXCHuAHwAagI8uBsiS1GbgB+AowPqtBqkAbsA74PnYnp44sSM0BNwN3A+dV2PYopnT2AHuBQ5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HnfMDNc5xAFA+DEYn7ccnq2+0v5b4hEaFP3u/xHKNuJy+DZwK0rvALc4ohVB1rAp6tAUSYmEb37OxZER3PnW4gR7fhmRqr9iIqcpKwRlPtVibTJaVqmV2H2ComS3kMbMKeQwtxqS44j8XpZGGS9OhPRdJ46ZI8NViTql/xoFzYz4NJZovrDKjVN/nJn7aYyLnDvwmVaJdQqave0rFVYN+EhfgE9/jWptZjVyZSUONGzJmvRtS7QsqdHiCFmbteVwIHnn5ZodHyJzk5tD7WFDkjrS9mzM8SFRRBBoPPTPSRNhv5jTf00SaxVRQPr1KMHL+dcg0dF1/laoJPl2cOHt/FASOQ2edYn0NFw31RUm7kplbblBr7Pc8hB9N0Tbf5p61dgckJpAamwOSE0gNTYHpCaQGpsDUhNIjVfvgD9WFsGCdX/VsgAAAABJRU5ErkJggg==)](https://wappsto.com)

SlxJsonRpc is a JsonRpc helper class, that uses pydantic.

SlxJsonRpc keep track of the JsonRpc schema, and procedure for each method.
It also ensures to route each message to where it is expected.

SlxJsonRpc is build to be both a JsonRpc server & client.
To enable the JsonRpc-server, the method_map need to be given.

### Installation using pip

The slxjsonrpc package can be installed using PIP (Python Package Index) as follows:

```bash
$ pip install slxjsonrpc
```

### Use case Examples

The given use case show how to use the slxJsonRpc Package.
It expected that you have a send & a receive function/method to transport
the Json RPC messages to and from the package.

The Client example code:
```python
from typing import List, Union, Literal

from enum import Enum
import slxjsonrpc


def send(data: str) -> None: ...


def receive() -> Union[str, bytes, dict]: ...


class MethodList(str, Enum):
    ADD = "add"
    PING = "ping"


params = {
    MethodList.ADD: List[Union[int, float]],
    MethodList.PING: None,
}

result = {
    MethodList.ADD: Union[int, float],
    MethodList.PING: Literal["pong"]
}

client_jsonrpc = slxjsonrpc.SlxJsonRpc(
    methods=MethodsList,
    result=result,
    params=params,
)

ok = None


def reply(reply_data):
    nonlocal ok
    ok = reply_data  # Will be "pong"


ping_package = client_jsonrpc.create_request(method=MethodList.PING, callback=reply)
send(ping_package.json(exclude_none=True))
data = receive()
client_jsonrpc.parser(data)

print(f"OK: {ok}")
```


The Server example code:
```python
from typing import List, Union, Literal

from enum import Enum
import slxjsonrpc


def send(data: str) -> None: ...


def receive() -> Union[str, bytes, dict]: ...


class MethodList(str, Enum):
    ADD = "add"
    PING = "ping"


params = {
    MethodList.ADD: List[Union[int, float]],
    MethodList.PING: None,
}

result = {
    MethodList.ADD: Union[int, float],
    MethodList.PING: Literal["pong"]
}


method_map = {
    MethodList.ADD: lambda data: sum(data),
    MethodList.PING: lambda data: "pong",
}


server_jsonrpc = slxjsonrpc.SlxJsonRpc(
    methods=MethodsList,
    result=result,
    params=params,
    method_cb=method_map,
)

data = receive()
return_data = server_jsonrpc.parser(data)
if return_data:
    send(return_data.json(exclude_none=True))
```


License
-------------------------------------------------------------------------------

This project is licensed under the Apache License 2.0 - see the [LICENSE.md](LICENSE.md) file for details.


v0.9.2 (August 17, 2023)
===============================================================================

## Added
 * RcpBatch is now iterable and behave more list a list.

## Fixed
 * Type hinting errors.
 * Most issues where the wrong combo of `exclude_unset` & `exclude_none` given to `model_dump_json` would result in a invalid JsonRpc.

## Changed
 * Notifications can now not trigger an Error Rpc reply. as per the specification.


v0.9.1 (August 4, 2023)
===============================================================================

## Fixed
 * Type hinting errors.
 * A method to param mapping error.

v0.9.0 (August 3, 2023)
===============================================================================

## Changed
 * Now using Pydantic version 2.
 * Now require python 3.7 or later.

v0.8.2 (December 13, 2021)
===============================================================================

## Added
 * Change-log

## Changed
 * How `create_request` adds a Result reply handling. So now it uses `_add_result_handling`, which mean it will be easier to hook into for work-a-rounds.


v0.8.1 (November 25, 2021)
===============================================================================

## Fixed
 * Type hinting errors.


v0.8.0 (November 12, 2021)
===============================================================================
## Added
 * First Release.