Skip to main content

JSON-RPC server based on fastapi

Project description

Description

JSON-RPC server based on fastapi:

https://fastapi.tiangolo.com

Installation

pip install fastapi-jsonrpc

Usage

pip install uvicorn
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(..., example='123'),
) -> str:
    if data == 'error':
        raise MyError(data={'details': 'error'})
    else:
        return data


app.bind_entrypoint(api_v1)


if __name__ == '__main__':
    import uvicorn
    uvicorn.run(app, port=5000, debug=True, access_log=False)

Go to:

http://127.0.0.1:5000/docs

Development

  1. Install poetry

    https://github.com/sdispater/poetry#installation

  2. Install dependencies

    poetry update
  3. Install dephell

    pip install dephell
  4. Regenerate setup.py

    dephell deps convert

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.19.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_jsonrpc-0.1.19-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file fastapi-jsonrpc-0.1.19.tar.gz.

File metadata

  • Download URL: fastapi-jsonrpc-0.1.19.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.17 CPython/3.7.3 Darwin/18.7.0

File hashes

Hashes for fastapi-jsonrpc-0.1.19.tar.gz
Algorithm Hash digest
SHA256 901056f15a8b0e6f628d1518c7837df872267ee56c0b8c1e3a40bd1c07a4877a
MD5 3ef34de776bde033f950cba192e8cb67
BLAKE2b-256 9c698fe7ed8a58a96f0550663400aa5f82ac0886138d3aa62532a64e04703cdf

See more details on using hashes here.

File details

Details for the file fastapi_jsonrpc-0.1.19-py3-none-any.whl.

File metadata

  • Download URL: fastapi_jsonrpc-0.1.19-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.17 CPython/3.7.3 Darwin/18.7.0

File hashes

Hashes for fastapi_jsonrpc-0.1.19-py3-none-any.whl
Algorithm Hash digest
SHA256 e6bcc38889c0dc75c174ce55fb36ecbf83c082b5633f141631d3f18e97213291
MD5 ee22cdd7a8dfa4c65d2294a2d441de06
BLAKE2b-256 c7093c1043a0e8c62d09c7a06788d95d84f9b7bd845074e525cec462b705c4d6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page