JSON-RPC server based on fastapi
Project description
Description
JSON-RPC server based on fastapi:
Installation
pip install fastapi-jsonrpc
Usage
pip install uvicorn
import fastapi_jsonrpc as jsonrpc
from fastapi_jsonrpc import Param
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 = Param(..., example='123'),
) -> str:
if data == 'error':
raise MyError(data={'details': 'error'})
return data
app.bind_entrypoint(api_v1)
if __name__ == '__main__':
import uvicorn
uvicorn.run(app, port=5000, debug=True, access_log=False)
Go to:
Development
Install poetry
Install dependencies
poetry update
Install dephell
pip install dephell
Regenerate setup.py
dephell deps convert
Changelog
[0.1.8] Push sources to github
[0.1.7]
Follow JSON-RPC specification in special cases:
Use aiojobs.Scheduler for batch requests
[0.1.6] Ability to write DataModel class in BaseError class scope
[0.1.5] Add error usage example to README.rst
[0.1.4] Add description to README.rst
[0.1.3] Fix README.rst
[0.1.2] Add usage example to README.rst
[0.1.1] README.rst
[0.1.0] Initial commit
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
fastapi-jsonrpc-0.1.8.tar.gz
(8.1 kB
view hashes)
Built Distribution
Close
Hashes for fastapi_jsonrpc-0.1.8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47b6c3dd7c2dc3745118ad21b843ba0d82016757469cab788a16d547b5aa1464 |
|
MD5 | 741df6a95c75fdd2c5893e566cd613da |
|
BLAKE2b-256 | acee8c65338661cfbd84f6d2622044a39e7705d258ad1f54999796d34b9d0725 |