{"id":1758,"library":"types-jsonschema","title":"Typing Stubs for jsonschema","description":"This package provides static type annotations (stubs) for the `jsonschema` library, enabling tools like `mypy` to perform static analysis on code that uses `jsonschema`. It's part of the typeshed project, a community effort to add types to popular Python packages. The current version, `4.26.0.20260408`, typically tracks the `jsonschema` library's version, with a datestamp for stub updates.","status":"active","version":"4.26.0.20260408","language":"en","source_language":"en","source_url":"https://github.com/python/typeshed","tags":["typing","stubs","jsonschema","type-checking","typeshed"],"install":[{"cmd":"pip install types-jsonschema","lang":"bash","label":"Install package"}],"dependencies":[{"reason":"Provides type hints for this runtime library; must be installed separately to use its functionality.","package":"jsonschema","optional":true}],"imports":[],"quickstart":{"code":"import jsonschema\nfrom typing import Any\n\n# Define a simple JSON schema\nmy_schema: dict[str, Any] = {\n    \"type\": \"object\",\n    \"properties\": {\n        \"name\": {\"type\": \"string\"},\n        \"age\": {\"type\": \"integer\", \"minimum\": 0}\n    },\n    \"required\": [\"name\", \"age\"]\n}\n\n# Valid data instance\nvalid_data = {\"name\": \"Alice\", \"age\": 30}\njsonschema.validate(valid_data, my_schema)\nprint(\"Valid data validated successfully.\")\n\n# Invalid data instance (type mismatch)\ninvalid_data_type = {\"name\": \"Bob\", \"age\": \"twenty\"}\ntry:\n    jsonschema.validate(invalid_data_type, my_schema)\nexcept jsonschema.ValidationError as e:\n    print(f\"Caught expected validation error for invalid type: {e.message}\")\n\n# Note: With 'types-jsonschema' installed, a type checker like MyPy\n# would analyze calls to `jsonschema.validate`, ensuring correct\n# argument types are passed based on the stubs.","lang":"python","description":"Demonstrates basic `jsonschema` validation. When `types-jsonschema` is installed, static type checkers like `mypy` can analyze calls to `jsonschema` functions, providing type hints for arguments and return values, and catching potential type-related errors in your use of `jsonschema` at design time."},"warnings":[{"fix":"Install the runtime library: `pip install jsonschema`.","message":"This package provides only type hints for static analysis; it does not include any runtime code for the `jsonschema` library itself. You must install `jsonschema` separately to use its functionality.","severity":"gotcha","affected_versions":"All"},{"fix":"Continue importing symbols directly from `jsonschema`. Ensure your type checker is configured to use installed stub packages.","message":"You do not directly import any symbols from `types_jsonschema`. Instead, you import from the `jsonschema` library (e.g., `import jsonschema`), and type checkers automatically discover and use the installed stubs.","severity":"gotcha","affected_versions":"All"},{"fix":"Always ensure your `types-jsonschema` stub version is compatible with your `jsonschema` runtime version to avoid unexpected type errors or missing type hints.","message":"The versioning `X.Y.Z.YYYYMMDD` indicates the `jsonschema` version the stubs are primarily for (`X.Y.Z`) and the date the stubs were last updated. While `types-jsonschema` aims to be compatible, it might occasionally lag behind the latest `jsonschema` releases.","severity":"gotcha","affected_versions":"All"},{"fix":"Always update `types-jsonschema` when upgrading to a new major version of `jsonschema` to ensure type hint accuracy and compatibility.","message":"Significant breaking changes in `jsonschema` itself (e.g., between major versions) may render older `types-jsonschema` stubs inaccurate or incompatible, leading to type errors or missing types during static analysis.","severity":"breaking","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}