Welcome to spectree’s documentation!¶
Yet another library to generate OpenAPI document and validate request & response with Python annotations.
Features¶
- Less boilerplate code, annotations are really easy-to-use
- Generate API document with Redoc UI or Swagger UI
- Validate query, JSON data, response data with pydantic
- Current support:
- Flask
- Falcon
- Starlette
Quick Start¶
install with pip: pip install spectree
Step by Step¶
- Define your data structure used in (query, json, headers, cookies,
resp) with
pydantic.BaseModel
- create
spectree.SpecTree
instance with the web framework name you are using, likeapi = SpecTree('flask')
api.validate
decorate the route withquery
json
headers
cookies
resp
tags
- access these data with
context(query, json, headers, cookies)
(of course, you can access these from the original place where the framework offered)- flask:
request.context
- falcon:
req.context
- starlette:
request.context
- flask:
- register to the web application
api.register(app)
- check the document at URL location
/apidoc/redoc
or/apidoc/swagger