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
Documentation
Documentation and links to additional resources can be found here: https://b34nst4lk.github.io/tornopen/
Acknowledgements
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
torn_open-0.0.3.tar.gz
(13.0 kB
view details)
Built Distribution
torn_open-0.0.3-py3-none-any.whl
(14.9 kB
view details)
File details
Details for the file torn_open-0.0.3.tar.gz
.
File metadata
- Download URL: torn_open-0.0.3.tar.gz
- Upload date:
- Size: 13.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 689ac019ec6c5ecbb5d8e9c67ae3b330708370eebeba5d6c3b007acc77228972 |
|
MD5 | 2bf6e4bfec5f0be276f93bdca0fdd6fc |
|
BLAKE2b-256 | e13ea0cbee36446255f389d3b5cf5ef63af37b932126f2a3c3c21fddef00a7ce |
File details
Details for the file torn_open-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: torn_open-0.0.3-py3-none-any.whl
- Upload date:
- Size: 14.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf3576d92f68197cd9bfab73c26a09ab07a9d3c6571f43b837e23fc7e2728d13 |
|
MD5 | 464232ccff7d788ad69d685c4bfee661 |
|
BLAKE2b-256 | b2f3314e6406224633829d02ef7d93ed564f486d27120494d20f25fa57ea8d9b |