JSON-RPC server based on fastapi
Project description
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/.
License
MIT — see LICENSE.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastapi_jsonrpc-3.4.3.tar.gz.
File metadata
- Download URL: fastapi_jsonrpc-3.4.3.tar.gz
- Upload date:
- Size: 445.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c19a5370876d2ab4219e9c7b46e40a173be32c67f63a6393ced13e7f59f49ed
|
|
| MD5 |
e33503f45eff21d2d9cc46baa215077d
|
|
| BLAKE2b-256 |
8b2ab0c86dca7336713ea2e47bdec6c8cf559c657e9d8b4bb82f0d95d3294e1a
|
File details
Details for the file fastapi_jsonrpc-3.4.3-py3-none-any.whl.
File metadata
- Download URL: fastapi_jsonrpc-3.4.3-py3-none-any.whl
- Upload date:
- Size: 23.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ecaa0d640f9654b0ae0a5b7ffae970009088e878bfdcb5de23c044716741a78
|
|
| MD5 |
45b0ef914c869c10c770cff6f465ca51
|
|
| BLAKE2b-256 |
cfa3ae8360dfbcfc7c87a5f069ec3290716004a733e7548670dd88d2e7d85f97
|