Flask-Pydantic

Flask extension that integrates Pydantic for typed request and response validation.

Library
PyPI
v0.14.0
434stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
45/100Fair
Development Activity0
Maintenance20
Community72
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
81/100Excellent
Architecture80
Code Quality82
Innovation70
Learning Curve90

Flask-Pydantic is a Flask extension that brings Pydantic’s typed data validation to Flask request handling. With a single validate decorator, it parses and validates query strings, JSON bodies, and form data against Pydantic models, then exposes the validated objects to your view function with proper type hints.

Part of the Pallets Community Ecosystem, the extension removes the boilerplate of manually reading and checking request parameters. Invalid input is rejected with structured error responses automatically, and response models can be serialized on the way out, giving Flask APIs the same ergonomic, model-driven validation popularized by modern typed frameworks.

What You Get

  • A validate decorator that parses query, body, and form parameters into Pydantic models
  • Typed access to validated data as function arguments or request attributes
  • Automatic 400 responses with structured validation error details
  • Optional response model serialization for consistent output
  • Compatibility with both Pydantic v1 and v2 style models

Common Use Cases

  • Validating JSON request bodies for Flask REST endpoints
  • Parsing and type-checking URL query parameters
  • Enforcing form-data schemas on submission handlers
  • Serializing responses through Pydantic models for consistent APIs

Under The Hood

Architecture - The extension is compact: flask_pydantic/core.py implements the validate decorator that inspects the request, builds the declared Pydantic models from query, body, and form data, and attaches results to Flask’s request proxy or passes them as arguments. flask_pydantic/converters.py adapts query-string parsing, and flask_pydantic/exceptions.py defines the validation error responses returned to clients.

Tech Stack - Pure Python built on Flask and Pydantic, with support for both Pydantic v1 and v2 models. It has no other runtime dependencies and installs as a standard Flask extension.

Code Quality - The tests directory includes functional tests (func), unit tests, a dedicated pydantic_v1 suite, and shared fixtures via conftest, exercising both validation success and error paths across Pydantic versions. Maintained under Pallets-Eco, the small codebase is easy to audit.

API Design - The API is intentionally minimal: import validate, annotate a view with query/body/form Pydantic models, and read typed data directly. It mirrors patterns developers know from FastAPI while staying idiomatic to Flask, keeping the learning curve short.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search