Skip to main content

Client and Validator of OpenAPI 3 Specifications

Project description

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

GitHub Actions Build Badge 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
import yaml

# 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.securitySchemes
api.authenticate('personalAccessToken', my_token)

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

# call an operation 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.securitySchemes
# Tuple with (username, password) as second argument
api.authenticate('basicAuth', ('username', 'password'))

Running Tests

This project includes a test suite, run via pytest. To run the test suite, ensure that you’ve installed the dependencies and then run pytest in the root of this project.

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.8.1.tar.gz (23.2 kB view details)

Uploaded Source

Built Distribution

openapi3-1.8.1-py2.py3-none-any.whl (27.2 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: openapi3-1.8.1.tar.gz
  • Upload date:
  • Size: 23.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.2 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.0

File hashes

Hashes for openapi3-1.8.1.tar.gz
Algorithm Hash digest
SHA256 cc696ce11088a7fbb5f366307b0aebd115528adfb401b3e817c520adf2e68f86
MD5 d46ec1dfa59c0a36e79dd8ed72de3ac2
BLAKE2b-256 7b0958889a60b8b4c1796b980b09b1fac752e5f29ff55bce93eeb900aff64389

See more details on using hashes here.

File details

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

File metadata

  • Download URL: openapi3-1.8.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 27.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.2 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.0

File hashes

Hashes for openapi3-1.8.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ce6c9fb455e76ec055b3f885808ec8b3565f7fdc6153761a9daa4efc6e45081b
MD5 1c6ff544b9296b4d26d2ba3ea7581a73
BLAKE2b-256 283db81f3f3437f726dfb165c2cff6e4fe3ff57f884e6ad4a449a0078843f944

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