Skip to main content
Yanked

This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Consider using release 9.0.2 instead.
Reason given by maintainers: Numpy version constraints are incorrect.

pydantic-numpy

Integrate NumPy into Pydantic, and provide tooling! NumpyModel make it possible to dump and load np.ndarray within model fields!

Install

pip install pydantic-numpy

Usage

For more examples see test_ndarray.py

import pydantic_numpy.dtype as pnd
from pydantic_numpy import NDArray, NDArrayFp32, NumpyModel


class MyPydanticNumpyModel(NumpyModel):
    K: NDArray[float, pnd.float32]
    C: NDArrayFp32  # <- Shorthand for same type as K


# Instantiate from array
cfg = MyPydanticNumpyModel(K=[1, 2])
# Instantiate from numpy file
cfg = MyPydanticNumpyModel(K={"path": "path_to/array.npy"})
# Instantiate from npz file with key
cfg = MyPydanticNumpyModel(K={"path": "path_to/array.npz", "key": "K"})

cfg.K
# np.ndarray[np.float32]

cfg.dump("path_to_dump_dir", "object_id")
cfg.load("path_to_dump_dir", "object_id")

NumpyModel.load requires the original mode, use model_agnostic_load when you have several models that may be the right model.

Data type (dtype) support!

This package also comes with pydantic_numpy.dtype, which adds subtyping support such as NDArray[float, pnd.float32]. All subfields must be from this package as numpy dtypes have no Pydantic support, which is implemented in this package through the generic class workflow.

Considerations

You can install from cheind's repository if you want Python 3.8 support, but this version only support Pydantic V1 and will not work with V2.

Licensing notice

As of version 3.0.0 the license has moved over to BSD-4. The versions prior are under the MIT license.

History

The original idea originates from this discussion, and forked from cheind's repository.

Metadata

Release files for pydantic-numpy 3.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydantic-numpy 3.0.0
File Size Uploaded
pydantic_numpy-3.0.0.tar.gz 10.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pydantic-numpy 3.0.0
File Interpreter ABI Platform
pydantic_numpy-3.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 24.1 kB

Release files / pydantic_numpy-3.0.0.tar.gz

Download URL pydantic_numpy-3.0.0.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
1ace95bcf32a21bd32978bbd86e92dcdddfe24b46cbc641fff0a6f6c030c37cf
BLAKE2b-256 checksum
How to use checksums
b1342c94571f143fe443de931e970810152e2b24e07ae1d486e815c99fb3ca58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.11.3 Linux/6.4.4-zen1-1-zen

Release files / pydantic_numpy-3.0.0-py3-none-any.whl

Download URL pydantic_numpy-3.0.0-py3-none-any.whl
Size 14.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
56ec3d901c00a7aa01fd174a690eeaa929576d18a8a6da2252dc1956b15def62
BLAKE2b-256 checksum
How to use checksums
de82765b8b4a0c588fab324ed17b221513a34ccff4ab43bb913dd78d9390c67d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.11.3 Linux/6.4.4-zen1-1-zen

Release history Release notifications | RSS feed

9.0.2

2 release files

9.0.1

2 release files

9.0.0

2 release files

8.0.1

2 release files

8.0.0

2 release files

7.0.0

2 release files

6.0.1

2 release files

6.0.0

2 release files

5.0.2

2 release files

5.0.1

2 release files

5.0.0

2 release files

4.2.0

2 release files

4.1.3

2 release files

4.1.2

2 release files

4.1.1

2 release files

4.1.0

2 release files

4.0.1

2 release files

4.0.0

2 release files

3.1.5

2 release files

3.1.4

2 release files

3.1.3

2 release files

3.1.2

2 release files

3.1.1

2 release files

3.1.0

2 release files

This release

3.0.0 This release

2 release files

2.2.2

2 release files

2.2.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page