Skip to main content

fastapi-jsonrpc

tests

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.

fastapi-jsonrpc Swagger UI

📚 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 endpoint
  • GET /docs — Swagger UI
  • GET /openapi.json — OpenAPI schema
  • GET /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 DataModel included in the schema.
  • Batch requests and notifications.
  • Context-manager JSON-RPC middlewares.
  • Optional Sentry integration (fastapi_jsonrpc.contrib.sentry.FastApiJsonRPCIntegration).
  • Optional OpenTelemetry integration — per-call traces, JSON-RPC error reporting and duration metrics. Install with pip install 'fastapi-jsonrpc[opentelemetry]'.
  • 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.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastapi-jsonrpc 4.1.0
File Size Uploaded Provenance Actions
fastapi_jsonrpc-4.1.0.tar.gz 522.7 kB Without provenance Details for fastapi_jsonrpc-4.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-jsonrpc 4.1.0
File Interpreter ABI Platform Actions
fastapi_jsonrpc-4.1.0-py3-none-any.whl Python 3 none any Details for fastapi_jsonrpc-4.1.0-py3-none-any.whl

Total release size: 552.8 kB

Release files / fastapi_jsonrpc-4.1.0.tar.gz

Download URL fastapi_jsonrpc-4.1.0.tar.gz
Size 522.7 kB
Tags Source
SHA-256 checksum
How to use checksums
28671b9a2fe232e2b1a06aedc172fea543ddcb3d0aeb0fd08ebaed1415c416e8
BLAKE2b-256 checksum
How to use checksums
76549ea35d348bcd2362b9d6f8ddded5058f33ad7b3c295f06c382fff14b281a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","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.1.0-py3-none-any.whl

Download URL fastapi_jsonrpc-4.1.0-py3-none-any.whl
Size 30.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c0a285f3a0d95399d557a6b2e211f9aa1686c10182de90955878cbd10a2b9f26
BLAKE2b-256 checksum
How to use checksums
cf25c151e891077f71a86b28335435b2eabbf009dc0b8dfae3d6d28d9e7e605b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for fastapi-jsonrpc 4.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

4.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page