Skip to main content

OpenAPI 2.0 (aka Swagger) and OpenAPI 3 spec validator

Project description


OpenAPI Spec Validator is a CLI, pre-commit hook and python package that validates OpenAPI Specs against the OpenAPI 2.0 (aka Swagger), OpenAPI 3.0 and OpenAPI 3.1 specification. The validator aims to check for full compliance with the Specification.


Check documentation to see more details about the features. All documentation is in the “docs” directory and online at


pip install openapi-spec-validator

Alternatively you can download the code and install from the repository:

pip install -e git+


CLI (Command Line Interface)

Straight forward way:

openapi-spec-validator openapi.yaml

pipes way:

cat openapi.yaml | openapi-spec-validator -

docker way:

docker run -v path/to/openapi.yaml:/openapi.yaml --rm pythonopenapi/openapi-spec-validator /openapi.yaml

or more pythonic way:

python -m openapi_spec_validator openapi.yaml

For more details, read about CLI (Command Line Interface).

pre-commit hook

-   repo:
    rev: 0.5.5 # The version to use or 'master' for latest
    -   id: openapi-spec-validator

For more details, read about pre-commit hook.

Python package

from openapi_spec_validator import validate_spec
from openapi_spec_validator.readers import read_from_filename

spec_dict, base_uri = read_from_filename('openapi.yaml')

# If no exception is raised by validate_spec(), the spec is valid.

validate_spec({'openapi': '3.1.0'})

Traceback (most recent call last):
OpenAPIValidationError: 'info' is a required property

For more details, read about Python package.


Copyright (c) 2017-2023, Artur Maciag, All rights reserved. Apache v2

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

openapi_spec_validator-0.7.0.tar.gz (36.7 kB view hashes)

Uploaded Source

Built Distribution

openapi_spec_validator-0.7.0-py3-none-any.whl (36.6 kB view hashes)

Uploaded Python 3

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