Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

validation for aiohttp swagger openAPI 3

Project description



Package for displaying swagger docs via different UI backends and optionally validating/parsing aiohttp requests using swagger specification 3.0, known as OpenAPI3.

Supported UI backends

Multiple UI backends can be used or UI backend can be disabled at all if only needed validation without being able to view documentation.

Disable validation

Pass validate=False to SwaggerDocs/SwaggerFile class, the default is True
Also, sometimes validation has to be disabled for a route, to do this you have to pass validate=False during the initialization of the route.
ex."/route", handler, validate=False), the default is True


  • python 3.6+
  • aiohttp >= 3.5.4
  • pyyaml == 5.3
  • attrs == 19.3.0
  • python-fastjsonschema == 2.14.3
  • strict_rfc3339 == 0.7
  • contextvars == 2.4 (for python 3.6 only)


  • only application/json and application/x-www-form-urlencoded supported for now, but you can create own handler
  • header/query parameters only supported simple/form array serialization, e.g. 1,2,3,4
  • see TODO below


pip install aiohttp-swagger3


from aiohttp import web
from aiohttp_swagger3 import SwaggerDocs, SwaggerUiSettings

async def get_one_pet(request: web.Request, pet_id: int) -> web.Response:
    Optional route description
    summary: Info for a specific pet
      - pets
      - name: pet_id
        in: path
        required: true
        description: The id of the pet to retrieve
          type: integer
          format: int32
        description: Expected response to a valid request
              $ref: "#/components/schemas/Pet"
    if pet_id not in['storage']:
        raise web.HTTPNotFound()
    return web.json_response(['storage'][pet_id])

def main():
    app = web.Application()
    swagger = SwaggerDocs(
        title="Swagger Petstore",
        web.get("/pets/{pet_id}", get_one_pet),
    app['storage'] = {}

More examples

How it helps


  • application/json
  • application/x-www-form-urlencoded (except array and object)
  • items
  • properties
  • pattern
  • required
  • enum
  • minimum, maximum
  • exclusiveMinimum, exclusiveMaximum
  • minLength, maxLength
  • minItems, maxItems
  • uniqueItems
  • minProperties, maxProperties
  • default (only primitives)
  • additionalProperties
  • nullable
  • allOf, oneOf, anyOf
  • string formats: date, date-time, byte, email, uuid, hostname, ipv4, ipv6
  • custom string format validators

TODO (raise an issue if needed)

  • multipleOf
  • not
  • allowEmptyValue
  • Common Parameters for All Methods of a Path (spec file only)
  • readOnly, writeOnly
  • more serialization methods, see:
  • encoding
  • form data serialization (array, object)
  • default (array, object)

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 aiohttp-swagger3, version 0.4.4
Filename, size File type Python version Upload date Hashes
Filename, size aiohttp_swagger3-0.4.4-py3-none-any.whl (1.7 MB) File type Wheel Python version py3 Upload date Hashes View
Filename, size aiohttp-swagger3-0.4.4.tar.gz (1.7 MB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page