knafeh 1.1.0

QUIC-based RPC library with Python bindings
Documentation
"""Example: Knafeh RPC client in Python.

Run with (after starting the server):
    python examples/python_client.py
"""

import json

import anyio
import knafeh
from knafeh import Client, TlsConfig


async def main() -> None:
    tls = TlsConfig.client_insecure()

    async with Client("localhost:4433", tls=tls) as client:
        # Unary RPC call.
        request = json.dumps({"name": "Knafeh"}).encode()
        response = await client.call("greeter/say_hello", request)
        print(f"say_hello: {json.loads(response)}")

        response = await client.call("greeter/say_goodbye", request)
        print(f"say_goodbye: {json.loads(response)}")

        # Echo.
        echo_data = json.dumps({"ping": "pong"}).encode()
        response = await client.call("echo/echo", echo_data)
        print(f"echo: {json.loads(response)}")


if __name__ == "__main__":
    anyio.run(main, backend="trio")