flask-pydantic-spec
generate OpenAPI document and validate request & response with Python annotations.
What it is and what it does
Flask Pydantic Spec is a library that integrates Pydantic validation and OpenAPI documentation generation into Flask applications. It lets you define request and response schemas using Pydantic models, then automatically validates incoming requests against those schemas and generates interactive API documentation (Redoc or Swagger UI). Instead of writing separate YAML specs or manual validation logic, you annotate your Flask route handlers with Pydantic models, and the library handles validation, error responses (422 on failure), and documentation generation.
The library depends on pydantic for schema definition and validation, and inflection for string transformations. It supports validation of query parameters, JSON bodies, headers, and cookies, plus response type declarations. When validation fails, it returns a 422 status with structured error details. You access validated data via a context object attached to the request, though you can also use Flask's standard request object. The library began as a fork of Spectree and aims to reduce boilerplate by combining documentation and validation in one annotation-driven interface.
Use it for:
- Build a REST API with automatic OpenAPI documentation and request validation without writing separate spec files.
- Validate incoming JSON payloads and query parameters against Pydantic models, returning 422 errors with detailed validation messages.
- Generate interactive Swagger UI or Redoc documentation automatically from your Flask route annotations.
- Enforce consistent request/response schemas across a Flask application using Pydantic's validation and serialization.
- Add before/after hooks to validation to log failures, record metrics, or customize error responses per endpoint.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Adds OpenAPI documentation generation and request/response validation to Flask applications using Pydantic models and Python annotations.
Yes, if you need OpenAPI documentation and Pydantic validation in Flask and can tolerate unclear licensing and aging maintenance. The library is low-friction to install and actively works with current Python versions (3.9–3.13), but verify the license status before use and be aware that the project shows limited community adoption (1 star, 262 days since last release). No known vulnerabilities.
Install
flask-pydantic-spec on PyPI
pip
pip install flask-pydantic-specuv
uv add flask-pydantic-specpoetry
poetry add flask-pydantic-specInstalling flask-pydantic-spec
Before you install
Low friction: pure Python wheel with only two runtime dependencies (pydantic and inflection). Last commit was recent; however, the project shows aging maintenance signals with only 1 star and 262 days since the last release.
License in practice
License status is unclear—no SPDX identifier or raw license text is available in the package metadata. Verify the actual license before using in proprietary or restricted contexts.
Quickstart
pip install flask-pydantic-spec
from flask import Flask
from pydantic import BaseModel
from flask_pydantic_spec import FlaskPydanticSpec, Response, Request
class UserModel(BaseModel):
name: str
age: int
app = Flask(__name__)
api = FlaskPydanticSpec('flask')
@app.route('/api/user', methods=['POST'])
@api.validate(body=Request(UserModel), resp=Response(HTTP_200=UserModel))
def create_user():
return {'name': 'alice', 'age': 18}
api.register(app)
app.run()
Requires Python 3.9 or later.
Verify before relying
- Whether the unclear license status is a blocker for your use case (no SPDX or raw license metadata available).
- Current maintenance commitment and roadmap—only 1 GitHub star and 262 days since last release suggest limited community adoption.
Package facts
| License | not declared (unclear) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — pydantic, inflection |
| Maintenance | aging — 262 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 77,274/month — #14,542 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: flask_pydantic_spec-0.8.7-py3-none-any.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
flask-openapi3Builds REST APIs on Flask with automatic…
permissive · top 15,000 on PyPI
Flask-PydanticAdds Pydantic model validation to Flask route…
permissive · top 15,000 on PyPI
spectreeGenerates OpenAPI documents and validates HTTP…
permissive · top 15,000 on PyPI
openapi-pydanticProvides Pydantic-based classes that implement…
permissive · top 1,000 on PyPI
openapi-schema-pydanticProvides Pydantic classes that map to the…
permissive · top 5,000 on PyPI
quart-schemaQuart-Schema adds schema validation and…
permissive · top 15,000 on PyPI
pydantic-handlebarsRenders Handlebars templates for composing LLM…
permissive · top 5,000 on PyPI
APIFlaskAPIFlask is a lightweight web API framework…
permissive · top 15,000 on PyPI
sanic-extSanic Extensions adds OpenAPI documentation,…
permissive · top 15,000 on PyPI
flask-swaggerExtracts Swagger 2.0 API specifications from…
permissive · top 15,000 on PyPI