Client and Validator of OpenAPI 3 Specifications
Project description
A Python OpenAPI 3 Specification client and validator for Python 3.
NOTE
This is a work in progress, and may change significantly in the future. Many features are presently absent, and many common cases may not be implemented.
Validation Mode
This module can be run against a spec file to validate it like so:
python3 -m openapi /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 still needs to be done:
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file openapi3-0.0.2.tar.gz
.
File metadata
- Download URL: openapi3-0.0.2.tar.gz
- Upload date:
- Size: 23.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4305b6c92d29510502b36e098a9154f75ac0dd4c254f82d46f0d1e517a7ff38e |
|
MD5 | 4583e990d27f487b07aef937d0e4852a |
|
BLAKE2b-256 | 736003b6585326f526332be2a0d861150de4a0385bea3109680d3ec3bba33c4c |
File details
Details for the file openapi3-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: openapi3-0.0.2-py3-none-any.whl
- Upload date:
- Size: 20.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 230c4cd3ed4b3ba4b0f19892a52e15c22306c674773c331be88a3c64245a5115 |
|
MD5 | ef9346ea801a13150a958f9272a62b37 |
|
BLAKE2b-256 | 4f0148878830c8a93f945073d20605feccaf5fbd9c981168b56ea813f81ad509 |