{"id":21743,"library":"pydantic-numpy","title":"Pydantic NumPy","description":"Integrate NumPy arrays into Pydantic models with type validation, shape constraints, and dtype checking. Currently version 9.0.1 (requires Python >=3.11, <3.15). Active development with frequent breaking changes across major versions.","status":"active","version":"9.0.1","language":"python","source_language":"en","source_url":"https://github.com/caniko/pydantic-numpy","tags":["pydantic","numpy","validation","data-science"],"install":[{"cmd":"pip install pydantic-numpy","lang":"bash","label":"Install"}],"dependencies":[{"reason":"Core dependency for array data types.","package":"numpy","optional":false},{"reason":"Required for model validation.","package":"pydantic","optional":false}],"imports":[{"wrong":"from pydantic_numpy import NDArray","symbol":"NDArray","correct":"from pydantic_numpy import NDArray"}],"quickstart":{"code":"from pydantic_numpy import NumpyModel, numpy_array\n\nclass MyModel(NumpyModel):\n    data: numpy_array(shape=(3, 4), dtype=float)\n\narray_instance = MyModel(data=[[1.0, 2.0, 3.0, 4.0], [5.0, 6.0, 7.0, 8.0], [9.0, 10.0, 11.0, 12.0]])\nprint(array_instance.data)","lang":"python","description":"Create a Pydantic model with a validated NumPy array field; shape and dtype constraints are enforced."},"warnings":[{"fix":"Update imports to 'from pydantic_numpy import NDArray' and review the migration guide.","message":"Breaking changes between major versions are common. For example, v8 changed the import path of NDArray from pydantic_numpy.typing to pydantic_numpy root. Always check the changelog when upgrading.","severity":"breaking","affected_versions":">=8.0.0"},{"fix":"Use 'field: numpy_array(...)' inside class definition, not as a function call.","message":"numpy_array is not a function; it's a special form used in type annotations. Attempting to call numpy_array(...) as a function will raise an error.","severity":"gotcha","affected_versions":"all"},{"fix":"Always provide shape as a tuple: shape=(3, 4) not shape=[3, 4].","message":"Shape validation uses tuples; incorrect shape syntax (e.g., using lists) may fail silently or raise unexpected errors.","severity":"gotcha","affected_versions":"all"},{"fix":"Check the latest documentation for current parameter names.","message":"Some older parameter names like 'strict' have been deprecated in favor of 'strict_mode' (or similar) in recent versions.","severity":"deprecated","affected_versions":">=8.0.0"}],"env_vars":null,"search_vec":"'3.11':22 '3.15':23 '9.0.1':19 'across':30 'activ':24 'array':5 'break':28 'chang':29 'check':16 'constraint':13 'current':17 'data':37 'data-sci':36 'develop':25 'dtype':15 'frequent':27 'integr':3 'major':31 'model':8 'numpi':2,4,34 'pydant':1,7,33 'python':21 'requir':20 'scienc':38 'shape':12 'type':10 'valid':11,35 'version':18,32","created_at":"2026-04-27T17:01:30.952213+00:00","updated_at":"2026-04-27T17:01:30.952213+00:00","problems":{"verify_error":"Traceback (most recent call last):\n  File \"<string>\", line 1, in <module>\nImportError: cannot import name 'NDArray' from 'pydantic_numpy' (/tmp/tmpjpb6fnbs/venv/lib/python3.12/site-packages/pydantic_numpy/__init__.py)"},"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"9.0.1","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/caniko/pydantic-numpy","docs":null,"changelog":null,"pypi":"https://pypi.org/project/pydantic-numpy/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization","data","ai-ml"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"import_fail","verified_at":"2026-07-03","last_verified":"2026-07-03","next_check":"2026-07-10","install_tag":null}}