Skip to main content

generate OpenAPI document and validate request&response with Python annotations.

Project description

Spectree

GitHub Actions pypi downloads versions Language grade: Python Documentation Status

Yet another library to generate OpenAPI document and validate request & response with Python annotations.

Features

  • Less boilerplate code, annotations are really easy-to-use :sparkles:
  • Generate API document with Redoc UI or Swagger UI :yum:
  • Validate query, JSON data, response data with pydantic :wink:
  • Current support:
    • Flask
    • Falcon
    • Starlette

Quick Start

install with pip: pip install spectree

Examples

Check the examples folder.

Step by Step

  1. Define your data structure used in (query, json, headers, cookies, resp) with pydantic.BaseModel
  2. create spectree.SpecTree instance with the web framework name you are using, like api = SpecTree('flask')
  3. api.validate decorate the route with
    • query
    • json
    • headers
    • cookies
    • resp
    • tags
  4. 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
  5. register to the web application api.register(app)
  6. check the document at URL location /apidoc/redoc or /apidoc/swagger

FAQ

ValidationError: missing field for headers

The HTTP headers' keys in Flask are capitalized, in Falcon are upper cases, in Starlette are lower cases.

Project details


Release history Release notifications | RSS feed

This version

0.2.0

Download files

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

Source Distribution

spectree-0.2.0.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

spectree-0.2.0-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file spectree-0.2.0.tar.gz.

File metadata

  • Download URL: spectree-0.2.0.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.4

File hashes

Hashes for spectree-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a96f28c09e5f863a70f7f5a8554c185d45ff8d972e9b4b0ca323651bb8ef37ff
MD5 f77bd93c07f14510114ccd05ca55638e
BLAKE2b-256 6667730754b85da3e33aa94f0de530665adcf22312b1f12ba9bafa49c552b8e9

See more details on using hashes here.

File details

Details for the file spectree-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: spectree-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 19.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.4

File hashes

Hashes for spectree-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7eeaafdc53f2481023b0fa00872514fb50640fba72eb9f1c9d1d27b8cf85766b
MD5 2add0502d5a879f67a48a16a32890495
BLAKE2b-256 ce7117d301ba3c6b27c15d045d8cfeb543218acbc3f0cb276b96b96ca55a52ff

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