openapi-schema-pydantic
OpenAPI (v3) specification schema as pydantic class
What it is and what it does
openapi-schema-pydantic wraps the OpenAPI v3 specification as a set of Pydantic data classes, letting you build and validate OpenAPI documents programmatically in Python. Instead of hand-writing JSON or YAML specs, you instantiate Pydantic objects (OpenAPI, Info, Operation, Response, etc.) that follow the official schema naming and structure, then serialize them to spec-compliant JSON or dict.
The package leverages Pydantic's validation and schema generation to handle the complexity of OpenAPI's nested structure. It supports both object-oriented construction and mixed dict/object input, and includes utilities to embed Pydantic model schemas directly into OpenAPI documents as JSON Schema references. It offers both OpenAPI 3.1.0 and 3.0.3 versions via separate import paths.
Use it for:
- Generate OpenAPI specs programmatically from Python code instead of maintaining separate YAML/JSON files.
- Validate OpenAPI documents at runtime using Pydantic's built-in validation before publishing or serving them.
- Embed Pydantic model schemas into OpenAPI definitions to keep request/response types in sync with your code.
- Build API documentation tooling that constructs OpenAPI specs from Python function signatures and type hints.
- Migrate or transform existing OpenAPI specs by parsing them into Pydantic objects, modifying them, and re-serializing.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides Pydantic classes that map to the OpenAPI v3 specification schema, enabling programmatic construction and validation of OpenAPI documents.
Yes, with conditions. The package is stable and widely used, but maintenance is dormant—last release was 2022-06-29. Install it if you need to work with OpenAPI specs in Python and can tolerate slow or no updates. Verify compatibility with your Pydantic version and confirm that OpenAPI 3.0.3 or 3.1.0 support meets your needs. No known security vulnerabilities.
Install
openapi-schema-pydantic on PyPI
pip
pip install openapi-schema-pydanticuv
uv add openapi-schema-pydanticpoetry
poetry add openapi-schema-pydanticInstalling openapi-schema-pydantic
Before you install
Low install friction with a single runtime dependency. Maintenance is dormant—last release was 2022-06-29, though the repository remains active and the package is widely used.
License in practice
MIT License (permissive). No restrictions on commercial or private use; you may modify and distribute freely with attribution.
Quickstart
pip install openapi-schema-pydantic
from openapi_schema_pydantic import OpenAPI, Info, Operation, Response
open_api = OpenAPI(
info=Info(title="My API", version="v1"),
paths={"/ping": {"get": Operation(responses={"200": Response(description="pong")})}}
)
print(open_api.json(by_alias=True, exclude_none=True))
Requires Python >=3.6.1; when serializing to JSON, must use by_alias=True and exclude_none=True to comply with OpenAPI standard.
Verify before relying
- Whether dormant maintenance status affects compatibility with recent OpenAPI spec updates or pydantic breaking changes.
- Support level for OpenAPI 3.1.0 vs 3.0.3 in production environments and tooling ecosystem.
- Compatibility with current versions of pydantic, especially pydantic v2.
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.6.1) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — pydantic |
| Maintenance | dormant — 1,507 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,085,006/month — #4,387 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: openapi_schema_pydantic-1.2.4-py3-none-any.whl
Tags
More WWW/HTTP packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
h11h11 is a pure-Python HTTP/1.1 protocol…
permissive · top 100 on PyPI
httpxHTTPX is a fully featured HTTP client library…
permissive · top 100 on PyPI
httpcoreA minimal low-level HTTP client library that…
permissive · top 100 on PyPI
aiohttpaiohttp is an async HTTP client and server…
permissive · top 100 on PyPI
openapi-pydanticProvides Pydantic-based classes that implement…
permissive · top 1,000 on PyPI
flask-pydantic-specAdds OpenAPI documentation generation and…
unclear · top 15,000 on PyPI
aiopenapi3Parses and validates OpenAPI 3 specifications…
permissive · top 15,000 on PyPI
flask-openapi3Builds REST APIs on Flask with automatic…
permissive · top 15,000 on PyPI
turnkey-sdk-typesProvides generated Pydantic type definitions…
permissive · top 15,000 on PyPI
open-data-contract-standardReads and writes YAML files conforming to the…
permissive · top 5,000 on PyPI
openapi-spec-validatorValidates OpenAPI specifications (versions 2.0,…
permissive · top 1,000 on PyPI
json-schema-to-pydanticAutomatically generates Pydantic v2 models from…
permissive · top 5,000 on PyPI
openapi-python-clientGenerates type-annotated Python HTTP clients…
permissive · top 5,000 on PyPI
schemathesisSchemathesis generates test cases from OpenAPI…
permissive · top 5,000 on PyPI