numpydantic
Type and shape validation and serialization for arbitrary array types in pydantic models
What it is and what it does
Numpydantic bridges the gap between pydantic's data validation and array libraries by letting you specify arrays with precise shape and dtype constraints in type annotations. It solves the problem that pydantic cannot natively validate numpy arrays or other array types without workarounds—numpydantic provides an NDArray type that works seamlessly in pydantic models while also supporting static type checking via a mypy plugin.
The package works with multiple array backends (numpy, dask, zarr, hdf5, video files) through a pluggable interface, so the same type annotation can validate arrays from different libraries. You can use NDArray outside pydantic too, for isinstance checks or as a callable validator. Serialization to JSON-compatible formats is built in, and the package generates correct JSON Schema for your models, making them interoperable.
Use it for:
- Validate image or video data in pydantic models with exact shape and dtype requirements before processing.
- Define reusable array type aliases (e.g., GRAYSCALE) and catch shape mismatches at type-check time with mypy.
- Accept arrays from multiple backends (numpy, dask, zarr) in the same model without writing separate validators.
- Serialize array-containing models to JSON with metadata sufficient to reconstruct them in their native format.
- Lazy-load large arrays from hdf5 or zarr without full validation overhead by leveraging backend metadata.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Numpydantic adds type annotations and validation for arrays with shape and dtype constraints in pydantic models, supporting numpy, dask, zarr, hdf5, and video files through a pluggable interface.
Yes. Numpydantic is actively maintained, has no known vulnerabilities, and solves a real problem—pydantic's inability to validate arrays with shape and dtype constraints. Low install friction, permissive license, and support for multiple array backends make it a practical choice for data science and scientific computing workflows that use pydantic for validation.
Install
numpydantic on PyPI
pip
pip install numpydanticuv
uv add numpydanticpoetry
poetry add numpydanticInstalling numpydantic
Before you install
Low friction: pure Python wheel with only three runtime dependencies (pydantic, numpy, typing-extensions). Actively maintained with a recent release 53 days ago and no known vulnerabilities.
License in practice
MIT license is permissive; you can use, modify, and distribute numpydantic freely in commercial and private projects with minimal restrictions.
Quickstart
pip install numpydantic
from pydantic import BaseModel
from numpydantic import NDArray, Shape
import numpy as np
class MyModel(BaseModel):
array: NDArray[Shape["3 x, 4 y, * z"], int]
model = MyModel(array=np.zeros((3, 4, 5), dtype=int))
Requires Python 3.10 or later; optional array-library extras (dask, hdf5, zarr, video) needed for those backends.
Verify before relying
- Whether the mypy plugin (introduced in 1.9.0) is production-ready and widely adopted.
- Performance overhead of validation on large arrays compared to raw numpy operations.
- Stability of the extensible specification syntax mentioned as planned for v2.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (<4.0,>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — pydantic, numpy, typing-extensions |
| Maintenance | actively maintained — 53 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 602,059/month — #5,817 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: numpydantic-1.10.0-py3-none-any.whl
Keywords: arrays, validation, serialization, numpy, pydantic
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pydantic-numpyIntegrates NumPy arrays into Pydantic models…
permissive · top 15,000 on PyPI
pydantic-zarrProvides Pydantic models for reading,…
permissive · top 15,000 on PyPI
nptypingProvides type hints and runtime type checking…
permissive · top 15,000 on PyPI
dyntasticDyntastic is a DynamoDB object-relational…
permissive · top 15,000 on PyPI
jaxtypingProvides type annotations and runtime…
permissive · top 5,000 on PyPI
pydantic_yamlPydantic-YAML adds YAML serialization and…
permissive · top 5,000 on PyPI
numpy-quaternionAdds a quaternion dtype to NumPy, enabling…
permissive · top 5,000 on PyPI
pydantic-extra-typesProvides additional type validators and…
permissive · top 1,000 on PyPI
ipydatawidgetsipydatawidgets provides Jupyter widgets for…
permissive · top 15,000 on PyPI
asdfASDF is a Python implementation of the Advanced…
unclear · top 15,000 on PyPI