Server
FastAPI Adapter
Mount pyRPC on a FastAPI application using mount_fastapi.
FastAPI Adapter
The FastAPI adapter exposes your pyRPC procedures at POST /rpc on a FastAPI app.
Installation
uv add pyrpc-core pyrpc-fastapiBasic Setup
from fastapi import FastAPI
from pyrpc_core import rpc
from pyrpc_fastapi import mount_fastapi
app = FastAPI()
@rpc
def add(a: int, b: int) -> int:
return a + b
mount_fastapi(app)This registers add in the global registry and mounts a POST /rpc endpoint that forwards requests to pyRPC.
How It Works
@rpcregisters functions in the default registry.mount_fastapi(app)adds a FastAPI route:- path:
/rpc - method:
POST - body: JSON-RPC request payload
- path:
The adapter calls handle_request(payload) from pyRPC, then returns the JSON-RPC response.