Skip to main content

openapi3

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.

Release files for openapi3 1.8.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for openapi3 1.8.2
File Size Uploaded
openapi3-1.8.2.tar.gz 23.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for openapi3 1.8.2
File Interpreter ABI Platform
openapi3-1.8.2-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 50.5 kB

Release files / openapi3-1.8.2.tar.gz

Download URL openapi3-1.8.2.tar.gz
Size 23.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a21a490573d89ca69ada7cbe585adb2fca4964257f6f3a1df531f12815455d2c
BLAKE2b-256 checksum
How to use checksums
940ae7862c7870926ecb86d887923e36b7853480a2a97430162df1b972bd9d5b
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / openapi3-1.8.2-py2.py3-none-any.whl

Download URL openapi3-1.8.2-py2.py3-none-any.whl
Size 27.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
0d8fd34f304b61bc64b1f48ed6c6dbcc03ca04a29bcfa84e40ec5d87648e4399
BLAKE2b-256 checksum
How to use checksums
5101c7bbf0531b03fd5305c9338fb358b71f8c87dd5791145f3771c051ece4be
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

1.8.2 This release

2 release files

1.8.1

2 release files

1.8.0

2 release files

1.7.0

2 release files

1.6.6

2 release files

1.6.5

2 release files

1.6.4

2 release files

1.6.3

2 release files

1.6.2

2 release files

1.6.1

2 release files

1.6.0

2 release files

1.5.0

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page