Skip to main content

Client and Validator of OpenAPI 3 Specifications

Project description

A Python OpenAPI 3 Specification client and validator for Python 3.

https://travis-ci.org/Dorthu/openapi3.svg?branch=master https://badge.fury.io/py/openapi3.svg

Validation Mode

This module can be run against a spec file to validate it like so:

python3 -m openapi3 /path/to/spec

Usage as a Client

This library also functions as an interactive client for arbitrary OpenAPI 3 specs. For example, using Linode’s OpenAPI 3 Specification for reference:

from openapi3 import OpenAPI

# load the spec file and read the yaml
with open('openapi.yaml') as f:
    spec = yaml.safe_load(f.read())

# parse the spec into python - this will raise if the spec is invalid
api = OpenAPI(spec)

# call operations and receive result models
regions = api.call_getRegions()

# authenticate using a securityScheme defined in the spec's components.securtiySchemes
api.authenticate('personalAccessToken', my_token)

# call an operation that requires authentication
linodes  = api.call_getLinodeInstances()

# call an opertaion with parameters
linode = api.call_getLinodeInstance(parameters={"linodeId": 123})

# the models returns are all of the same (generated) type
print(type(linode))                      # openapi.schemas.Linode
type(linode) == type(linodes.data[0])    # True

# call an operation with a request body
new_linode = api.call_createLinodeInstance(data={"region":"us-east","type":"g6-standard-2"})

# the returned models is still of the correct type
type(new_linode) == type(linode)     # True

HTTP basic authentication and HTTP digest authentication works like this:

# authenticate using a securityScheme defined in the spec's components.securtiySchemes
# Tuple with (username, password) as second argument
api.authenticate('basicAuth', ('username', 'password'))

Roadmap

The following features are planned for the future:

  • Request body models, creation, and validation.

  • Parameters interface with validation and explicit typing.

  • Support for more authentication types.

  • Support for non-json request/response content.

  • Full support for all objects defined in the specification.

Project details


Download files

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

Source Distribution

openapi3-1.0.0.tar.gz (23.2 kB view details)

Uploaded Source

Built Distribution

openapi3-1.0.0-py2.py3-none-any.whl (21.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file openapi3-1.0.0.tar.gz.

File metadata

  • Download URL: openapi3-1.0.0.tar.gz
  • Upload date:
  • Size: 23.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for openapi3-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d0c84c942bc89c323069db6ea1e8c7aca470c2acda427d113dae3d92bdd086e6
MD5 d7cbba22a804b35b25089355fddf81ed
BLAKE2b-256 359cb984cccbd9f66316f9ed7ebf22523a73f196cac8786efdca30e37069d759

See more details on using hashes here.

File details

Details for the file openapi3-1.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: openapi3-1.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 21.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for openapi3-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2f7fd132fc62b3d6a1dea9d160c82849dd6eb3e4ee7b72f336bf666de473eaae
MD5 ae1be57c4189e31241eebda5a36dbb9f
BLAKE2b-256 5afabeec306d8ecfc146a8953122b77d7c5898c54e0c3f25bd82dac7f30a4c69

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