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.web import AnnotatedHandler, Application
from torn_open.models import RequestModel, ResponseModel, ClientError
from torn_open.api_spec import 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
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.1.tar.gz
(10.8 kB
view details)
Built Distribution
torn_open-0.0.1-py3-none-any.whl
(12.0 kB
view details)
File details
Details for the file torn_open-0.0.1.tar.gz
.
File metadata
- Download URL: torn_open-0.0.1.tar.gz
- Upload date:
- Size: 10.8 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a9b9f4a93dd0790675362276777cd6389afb1e19ec1c16a47d8f0fc08935ae4 |
|
MD5 | d61ae1732b6e40e3c1bcf418d545b5e1 |
|
BLAKE2b-256 | 1dd58382575d100c8e20b6fd67904bef535aa71f596841a9e990d49f6523d0f3 |
File details
Details for the file torn_open-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: torn_open-0.0.1-py3-none-any.whl
- Upload date:
- Size: 12.0 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | dabb9a15790c7faa3407a0f7af3d15bfdd43617d3a63b2069cdc5d174dd2556a |
|
MD5 | 4a9d726239b813a8bcd70837982bc51e |
|
BLAKE2b-256 | 266b67ba93805ee5ca738362a9478f166aef452ea55d1b09b3a8ab663f0b5a38 |