Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Framework for Quart to add swagger generation to routes and restful resources

Project description

Documentation can be found on

Quart-OpenAPI is an extension for Quart that adds support for generating a openapi.json file using openapi 3.0. If you are familiar with Quart, this just wraps around it to add a openapi.json route similar to Flask-RESTX generating a swagger.json route and adds a Resource base class for building RESTful APIs.


Quart-OpenAPI requires Python 3.6+ because Quart requires it.

Starting from version 1.6.0, Quart-OpenAPI requires python 3.7+ in order to avoid having to maintain multiple versions of function definitions for compatibility with the older versions of Quart that supported Python 3.6.


You can install via pip

$ pip install quart-openapi

If you are developing the module and want to also be able to build the documentation, make sure to also install the dependencies from the extras ‘doc’ package like so:

$ pip install 'quart-openapi[doc]'
$ python build_sphinx

Quick Start

If you’re familiar with Quart then the quick start doesn’t change much:

from quart_openapi import Pint, Resource

app = Pint(__name__, title='Sample App')

class Root(Resource):
  async def get(self):
    '''Hello World Route

    This docstring will show up as the description and short-description
    for the openapi docs for this route.
    return "hello"

This is equivalent to using the following with Quart as normal:

from quart import Quart
app = Quart(__name__)

async def hello():
  return "hello"

Except that by using Pint and Resource it will also add a route for ‘/openapi.json’ which will contain the documentation of the route and use the docstring for the description.

Unit Tests

Unit tests can be run through setuptools also:

$ python test

Request Validation

Request validation like you can get with Flask-RESTX!

You can either create validator models on the fly or you can create a jsonschema document for base models and then use references to it. For an on-the-fly validator:

expected = app.create_validator('sample_request', {
  'type': 'object',
  'properties': {
    'foobar': {
      'type': 'string'
    'baz': {
      'oneOf': [
        { 'type': 'integer' },
        { 'type': 'number', 'format': 'float' }

class Sample(Resource):
  async def post(self):
    # won't get here if the request didn't match the expected schema
    data = await request.get_json()
    return jsonify(data)

The default content type is ‘application/json’, but you can specify otherwise in the decorator:

  "$schema": "",
  "id": "schema.json",
  "components": {
    "schemas": {
      "binaryData": {
        "type": "string",
        "format": "binary"
app = Pint(__name__, title='Validation Example',
stream = app.create_ref_validator('binaryData', 'schemas')

class Binary(Resource):
  @app.expect((stream, 'application/octet-stream',
               {'description': 'gzip compressed data'}))
  @app.response(HTTPStatus.OK, 'Success')
  async def post(self):
    # if the request didn't have a 'content-type' header with a value
    # of 'application/octet-stream' it will be rejected as invalid.
    raw_data = await request.get_data(raw=True)
    # ... do something with the data
    return "Success!"

In the example above, it’ll open, read, and json parse the file schema.json and then use it as the basis for referencing models and creating validators. Currently the validator won’t do more than validate content-type for content-types other than ‘application/json’.

Project details

Download files

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

Files for quart-openapi, version 1.7.1
Filename, size File type Python version Upload date Hashes
Filename, size quart_openapi-1.7.1-py3.7.egg (49.1 kB) File type Egg Python version 3.7 Upload date Hashes View
Filename, size quart_openapi-1.7.1-py3-none-any.whl (23.3 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size quart-openapi-1.7.1.tar.gz (21.9 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page