skillfed

numpydantic

Type and shape validation and serialization for arbitrary array types in pydantic models

numpydantic v1.10.0 602.1K downloads/30d#5,817 on PyPI149
Permissive license MIT Active released

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 numpydantic

uv

uv add numpydantic

poetry

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

Development Status :: 5 - Production/StableFramework :: PydanticFramework :: Pydantic :: 2Intended Audience :: DevelopersIntended Audience :: Science/ResearchLicense :: OSI Approved :: MIT LicenseNatural Language :: EnglishOperating System :: MacOSOperating System :: Microsoft :: WindowsOperating System :: POSIX :: LinuxProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.9Topic :: File Formats :: JSON :: JSON SchemaTopic :: Utilities

Tags

pydantic array validationnumpy type hints with shapearray dtype and shape checkingtyped numpy arrays pydanticmulti-backend array validationndarray type annotationsarray serialization pydantic
array-validationtype-checkingdata-science

More Utilities packages