Skip to main content

Tornado x OpenAPI x Redoc

Project description

TornOpen

TornOpen is an extension of Tornado that relies on both Python's type annotation and pydantic to generate OpenAPI compliant documentation using apispec for Redoc

Supports

  • For Python versions 3.6 to 3.9, Tornado versions 4.5 to 6.1 are supported
  • For Python version 3.10, Tornado versions 6.0 to 6.1 are supported

Installation

pip install torn-open

Usage

Example Code

from typing import Optional
from tornado.web import url
from tornado.ioloop import IOLoop

from torn_open import (
    AnnotatedHandler,
    Application,
    RequestModel,
    ResponseModel,
    ClientError,
    tags,
    summary,
)


class MyRequestModel(RequestModel):
    """
    Docsting here will show up as description of the request model on redoc
    """

    var1: str
    var2: int


class MyResponseModel(ResponseModel):
    """
    Docsting here will show up as description of the response on redoc
    """

    path_param: str
    query_parm: int
    req_body: MyRequestModel


class MyAnnotatedHandler(AnnotatedHandler):
    @tags("tag_1", "tag_2")
    @summary("this is a summary")
    def post(
        self,
        *,
        path_param: str,
        query_param: Optional[int] = 1,
        req_body: MyRequestModel,
    ) -> MyResponseModel:
        """
        Docstrings will show up as descriptions on redoc
        """
        try:
            """do something here"""
        except:
            raise ClientError(status_code=403, error_type="forbiddon")
        return MyResponseModel(
            path_param=path_param,
            query_param=query_param,
            req_body=req_body,
        )


def make_app():
    return Application(
        [
            url(r"/annotated/(?P<path_param>[^/]+)", MyAnnotatedHandler),
        ],
    )


if __name__ == "__main__":
    app = make_app()
    app.listen(8888)
    IOLoop.current().start()

Result

Acknowledgements

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torn_open-0.0.2.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

torn_open-0.0.2-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file torn_open-0.0.2.tar.gz.

File metadata

  • Download URL: torn_open-0.0.2.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for torn_open-0.0.2.tar.gz
Algorithm Hash digest
SHA256 15b5b5dc70a0479cfce55e09858feeb26fc65675f1fadf3e1726290185a06b52
MD5 5e79e2d6d2a9843d2b69dd4883c557d5
BLAKE2b-256 f6a6740b6c5cee105a9d054ab7d78046666098be358212169b57b8141d60c620

See more details on using hashes here.

File details

Details for the file torn_open-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: torn_open-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for torn_open-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 40d329e0d3b0891fcf4828e50a4793b9cc14dc9423bbfa7ab42b05f5b44ac1d5
MD5 ecf224d716ef6fa88eb63ec3468e739e
BLAKE2b-256 2acb8bf79039a1348438b77ce55c0c3e5db157f458ce2477151f327389c05c68

See more details on using hashes here.

Supported by

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