--- id: numpydantic version: "1.10.0" license: MIT license_treatment: permissive maintenance: active --- # numpydantic — Type and shape validation and serialization for arbitrary array types in pydantic models License: permissive · Maintenance: active · Downloads: 602.1K/mo ## 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 above — 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 pip install numpydantic uv add numpydantic poetry add numpydantic ## Installing 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_current - Install friction: low - Maintenance: active - Downloads: 602.1K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags pydantic array validation, numpy type hints with shape, array dtype and shape checking, typed numpy arrays pydantic, multi-backend array validation, ndarray type annotations, array serialization pydantic, array-validation, type-checking, data-science [View on SkillFed](https://skillfed.io/packages/numpydantic) · [View on PyPI](https://pypi.org/project/numpydantic/)