skillfed

flask-pydantic-spec

generate OpenAPI document and validate request & response with Python annotations.

flask-pydantic-spec v0.8.7 77.3K downloads/30d#14,542 on PyPI1
License unclear AGING released

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

uv

uv add flask-pydantic-spec

poetry

poetry add flask-pydantic-spec

Installing 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

Operating System :: OS IndependentProgramming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.9Topic :: Software Development :: Libraries :: Python Modules

Tags

flask openapi documentationpydantic request validation flaskapi spec generation pythonflask swagger redocautomatic api documentationflask request validationopenapi schema flask
openapi-generationrequest-validationflask-integration

More Python Modules packages