{"id":13737495,"url":"https://github.com/cheind/pydantic-numpy","last_synced_at":"2025-08-23T18:15:10.065Z","repository":{"id":37981533,"uuid":"473865510","full_name":"cheind/pydantic-numpy","owner":"cheind","description":"Seamlessly integrate numpy arrays into pydantic models.","archived":false,"fork":false,"pushed_at":"2022-12-09T11:37:55.000Z","size":46,"stargazers_count":59,"open_issues_count":3,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-14T00:17:04.985Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cheind.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-03-25T04:15:58.000Z","updated_at":"2025-04-03T14:49:07.000Z","dependencies_parsed_at":"2023-01-25T16:00:38.006Z","dependency_job_id":null,"html_url":"https://github.com/cheind/pydantic-numpy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cheind/pydantic-numpy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheind%2Fpydantic-numpy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheind%2Fpydantic-numpy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheind%2Fpydantic-numpy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheind%2Fpydantic-numpy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cheind","download_url":"https://codeload.github.com/cheind/pydantic-numpy/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheind%2Fpydantic-numpy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271760532,"owners_count":24816441,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T03:01:50.369Z","updated_at":"2025-08-23T18:15:10.043Z","avatar_url":"https://github.com/cheind.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"[![Build Status](https://github.com/cheind/pydantic-numpy/actions/workflows/python-package.yml/badge.svg)](https://github.com/cheind/pydantic-numpy/actions/workflows/python-package.yml)\n\n# pydantic-numpy\n\nThis library provides support for integrating numpy `np.ndarray`'s into pydantic models.\n\n## Usage\n\nFor more examples see [test_ndarray.py](./tests/test_ndarray.py)\n\n```python\nfrom pydantic import BaseModel\n\nimport pydantic_numpy.dtype as pnd\nfrom pydantic_numpy import NDArray, NDArrayFp32\n\n\nclass MyPydanticNumpyModel(BaseModel):\n    K: NDArray[pnd.float32]\n    C: NDArrayFp32  # \u003c- Shorthand for same type as K\n\n\n# Instantiate from array\ncfg = MyPydanticNumpyModel(K=[1, 2])\n# Instantiate from numpy file\ncfg = MyPydanticNumpyModel(K={\"path\": \"path_to/array.npy\"})\n# Instantiate from npz file with key\ncfg = MyPydanticNumpyModel(K={\"path\": \"path_to/array.npz\", \"key\": \"K\"})\n\ncfg.K\n# np.ndarray[np.float32]\n```\n\n### Subfields\n\nThis package also comes with `pydantic_numpy.dtype`, which adds subtyping support such as `NDArray[pnd.float32]`. All subfields must be from this package as numpy dtypes have no [Pydantic support](https://pydantic-docs.helpmanual.io/usage/types/#generic-classes-as-types).\n\n## Install\n\nVia github\n\n```shell\npip install git+https://github.com/cheind/pydantic-numpy.git\n```\n\nVia PyPi (note that the package might be outdated)\n\n```shell\npip install pydantic-numpy\n```\n\n## History\n\nThe original idea originates from [this discussion](https://gist.github.com/danielhfrank/00e6b8556eed73fb4053450e602d2434), but stopped working for `numpy\u003e=1.22`. This repository picks up where the previous discussion ended\n\n-   added designated repository for better handling of PRs\n-   added support for `numpy\u003e1.22`\n-   Dtypes are no longer strings but `np.generics`. I.e. `NDArray['np.float32']` becomes `NDArray[np.float32]`\n-   added automated tests and continuous integration for different numpy/python versions\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcheind%2Fpydantic-numpy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcheind%2Fpydantic-numpy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcheind%2Fpydantic-numpy/lists"}