skillfed

openapi-schema-pydantic

OpenAPI (v3) specification schema as pydantic class

openapi-schema-pydantic v1.2.4 1.1M downloads/30d#4,387 on PyPI122
Permissive license DORMANT released

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-pydantic

uv

uv add openapi-schema-pydantic

poetry

poetry add openapi-schema-pydantic

Installing 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

License :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3

Tags

openapi schema pydantic modelsopenapi v3 specification classesconstruct openapi documents programmaticallyopenapi schema validationpydantic openapi definitionsopenapi 3.0.3 and 3.1.0 schema
openapiapi-specificationschema-validation

More WWW/HTTP packages