Transport agnostic framework for developing OpenRPC servers.
Project description
Python OpenRPC
Documentation: https://python-openrpc.burkard.cloud
Source Code: https://gitlab.com/mburkard/openrpc
Python OpenRPC is a transport agnostic framework for quickly and easily developing OpenRPC servers in Python.
Requirements
- Python 3.9+
- Pydantic for data models.
Installation
OpenRPC is on PyPI and can be installed with:
pip install openrpc
Or with Poetry
poetry add openrpc
Example
This is a minimal OpenRPC server using a Sanic websocket server as the transport method.
import asyncio
from openrpc import RPCServer
from sanic import Request, Sanic, Websocket
app = Sanic("DemoServer")
rpc = RPCServer(title="DemoServer", version="1.0.0")
@rpc.method()
async def add(a: int, b: int) -> int:
return a + b
@app.websocket("/api/v1/")
async def ws_process_rpc(_request: Request, ws: Websocket) -> None:
async def _process_rpc(request: str) -> None:
json_rpc_response = await rpc.process_request_async(request)
if json_rpc_response is not None:
await ws.send(json_rpc_response)
async for msg in ws:
asyncio.create_task(_process_rpc(msg))
if __name__ == "__main__":
app.run()
Example In
{
"id": 1,
"method": "add",
"params": {
"a": 1,
"b": 3
},
"jsonrpc": "2.0"
}
Example Result Out
{
"id": 1,
"result": 4,
"jsonrpc": "2.0"
}
Template App
You can bootstrap your OpenRPC server by cloning the template app.
Support the Developer
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
openrpc-7.3.8.tar.gz
(16.4 kB
view hashes)
Built Distribution
openrpc-7.3.8-py3-none-any.whl
(20.6 kB
view hashes)