openapi-spec-validator 0.8.4


pip install openapi-spec-validator

  Latest version

Released: Mar 01, 2026


Meta
Author: Artur Maciag
Requires Python: >=3.10,<4.0

Classifiers

Development Status
  • 4 - Beta

Intended Audience
  • Developers

Topic
  • Software Development :: Libraries

Operating System
  • OS Independent

Programming Language
  • Python :: 3
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13
  • Python :: 3.14

Typing
  • Typed
https://img.shields.io/docker/v/pythonopenapi/openapi-spec-validator.svg?color=%23086DD7&label=docker%20hub&sort=semver https://img.shields.io/pypi/v/openapi-spec-validator.svg https://img.shields.io/codecov/c/github/python-openapi/openapi-spec-validator/master.svg?style=flat https://img.shields.io/pypi/pyversions/openapi-spec-validator.svg https://img.shields.io/pypi/format/openapi-spec-validator.svg https://img.shields.io/pypi/status/openapi-spec-validator.svg

About

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 OpenAPI 3.1 and OpenAPI 3.2 specification. The validator aims to check for full compliance with the Specification.

Documentation

Check documentation to see more details about the features. All documentation is in the “docs” directory and online at openapi-spec-validator.readthedocs.io

Installation

pip install openapi-spec-validator

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

pip install -e git+https://github.com/python-openapi/openapi-spec-validator.git#egg=openapi_spec_validator

Usage

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

repos:
-   repo: https://github.com/python-openapi/openapi-spec-validator
    rev: 0.8.4 # The version to use or 'master' for latest
    hooks:
    -   id: openapi-spec-validator

For more details, read about pre-commit hook.

Python package

from openapi_spec_validator import validate
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(), the spec is valid.
validate(spec_dict)

# Example of an intentionally invalid spec.
invalid_spec = {'openapi': '3.1.0'}

validate(invalid_spec)

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

For more details, read about Python package.

Performance tuning

You can tune resolved-path caching with an environment variable:

OPENAPI_SPEC_VALIDATOR_RESOLVED_CACHE_MAXSIZE=2048

Rules:

  • Default is 128.

  • Set 0 to disable the resolved cache.

  • Invalid values (non-integer or negative) fall back to 128.

You can also choose schema validator backend:

OPENAPI_SPEC_VALIDATOR_SCHEMA_VALIDATOR_BACKEND=jsonschema-rs

Allowed values are auto (default), jsonschema, and jsonschema-rs. Invalid values raise a warning and fall back to auto.

If you select the jsonschema-rs backend, make sure the optional jsonschema-rs package is installed:

pip install jsonschema-rs

License

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

Extras: None
Dependencies:
jsonschema (<4.25.0,>=4.24.0)
jsonschema-path (<0.5.0,>=0.4.3)
lazy-object-proxy (<2.0,>=1.7.1)
openapi-schema-validator (<0.9.0,>=0.7.3)
pydantic (<3.0.0,>=2.0.0)
pydantic-settings (<3.0.0,>=2.0.0)