fastapi-jsonrpc
JSON-RPC 2.0 server on top of FastAPI. Write JSON-RPC methods the same way you write FastAPI endpoints and get OpenAPI, Swagger UI and OpenRPC for free.
📚 Documentation: https://smagafurov.github.io/fastapi-jsonrpc/
Install
pip install fastapi-jsonrpc
Minimal example
import fastapi_jsonrpc as jsonrpc
from pydantic import BaseModel
from fastapi import Body
app = jsonrpc.API()
api_v1 = jsonrpc.Entrypoint('/api/v1/jsonrpc')
class MyError(jsonrpc.BaseError):
CODE = 5000
MESSAGE = 'My error'
class DataModel(BaseModel):
details: str
@api_v1.method(errors=[MyError])
def echo(data: str = Body(..., examples=['hello'])) -> str:
if data == 'error':
raise MyError(data={'details': 'boom'})
return data
app.bind_entrypoint(api_v1)
if __name__ == '__main__':
import uvicorn
uvicorn.run('app:app', port=5000, access_log=False)
Run it with uvicorn and open:
POST /api/v1/jsonrpc— JSON-RPC endpointGET /docs— Swagger UIGET /openapi.json— OpenAPI schemaGET /openrpc.json— OpenRPC schema
Features
- All of FastAPI —
Depends,Body,Header,Cookie, Pydantic models, async/await. - Auto-generated OpenAPI and OpenRPC schemas.
- Typed errors with Pydantic
DataModelincluded in the schema. - Batch requests and notifications.
- Context-manager JSON-RPC middlewares.
- Optional Sentry integration (
fastapi_jsonrpc.contrib.sentry.FastApiJsonRPCIntegration). - Pytest plugin for capturing JSON-RPC errors in tests.
See the full docs at https://smagafurov.github.io/fastapi-jsonrpc/.
Development
# Install dependencies
uv sync --frozen --group dev
# Run tests
uv run --frozen python -m pytest
# Run a single test
uv run --frozen python -m pytest tests/test_jsonrpc.py::test_name -x
# Change dependencies — edit pyproject.toml, then:
uv lock
# Build and publish
uv build
uv publish
License
MIT — see LICENSE.
Metadata
Release files for fastapi-jsonrpc 4.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fastapi_jsonrpc-4.0.1.tar.gz | 497.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fastapi_jsonrpc-4.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 525.0 kB
Release files / fastapi_jsonrpc-4.0.1.tar.gz
| Download URL | fastapi_jsonrpc-4.0.1.tar.gz |
|---|---|
| Size | 497.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e8208851a095f20902d072f7eac1be9f87cbac14f71d52617f0daa92aef4abd1
|
|
BLAKE2b-256 checksum How to use checksums |
ea8fb3dc3872674f6856cd19154126c31120f2cbfb16141e541ab6f1ffce1952
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / fastapi_jsonrpc-4.0.1-py3-none-any.whl
| Download URL | fastapi_jsonrpc-4.0.1-py3-none-any.whl |
|---|---|
| Size | 27.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
76d91520604eaa4472b356c3afa2e301d72ba5e9c2229fd918999f4f44a2b7a1
|
|
BLAKE2b-256 checksum How to use checksums |
6379ca90ce5bba604d40b9fe174180829d8cd0663418bcb4244619e38a5f1107
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|