Registry / type-stubs / types-jsonschema

types-jsonschema

JSON →
library4.26.0.20260408pypypiunverified

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.

pip install types-jsonschema
INSTALL
IMPORT
SIG · TYPES-JSONSCHEMA
T
types-jsonschema
type-stubspythonv4.26.0.20260408
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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.

import jsonschema from typing import Any # Define a simple JSON schema my_schema: dict[str, Any] = { "type": "object", "properties": { "name": {"type": "string"}, "age": {"type": "integer", "minimum": 0} }, "required": ["name", "age"] } # Valid data instance valid_data = {"name": "Alice", "age": 30} jsonschema.validate(valid_data, my_schema) print("Valid data validated successfully.") # Invalid data instance (type mismatch) invalid_data_type = {"name": "Bob", "age": "twenty"} try: jsonschema.validate(invalid_data_type, my_schema) except jsonschema.ValidationError as e: print(f"Caught expected validation error for invalid type: {e.message}") # Note: With 'types-jsonschema' installed, a type checker like MyPy # would analyze calls to `jsonschema.validate`, ensuring correct # argument types are passed based on the stubs.
Debug
Known issues
gotchaThis 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.
fix
Install the runtime library: `pip install jsonschema`.
affects: All
gotchaYou 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.
fix
Continue importing symbols directly from `jsonschema`. Ensure your type checker is configured to use installed stub packages.
affects: All
gotchaThe 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.
fix
Always ensure your `types-jsonschema` stub version is compatible with your `jsonschema` runtime version to avoid unexpected type errors or missing type hints.
affects: All
breakingSignificant 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.
fix
Always update `types-jsonschema` when upgrading to a new major version of `jsonschema` to ensure type hint accuracy and compatibility.
affects: All
Errors
Common errors & fixes
Missing type stubs for module 'jsonschema' (or corresponding PyPI package 'jsonschema').
Mypy cannot find static type information for the `jsonschema` library, typically because the `types-jsonschema` stub package is not installed.
fix
Install the type stub package: `pip install types-jsonschema`
ModuleNotFoundError: No module named 'types_jsonschema'
The user is attempting to import from the stub package directly, but `types-jsonschema` is for static analysis and not intended for runtime import; the actual runtime library is `jsonschema`.
fix
Import from the `jsonschema` library instead: `from jsonschema import validate`
Module 'jsonschema' has no 'Draft7Validator' member
Mypy cannot find the specified member (`Draft7Validator` or similar, e.g., `exceptions.ValidationError`) within the `jsonschema` module, often due to missing type stubs or a version mismatch between the `jsonschema` library and its installed stubs.
fix
Install the `types-jsonschema` package (`pip install types-jsonschema`) and ensure it's compatible with your `jsonschema` version.
error: Argument "validator" to "validate" of "jsonschema" has incompatible type "..." (expression has type "...", expected "...")
Mypy detects that the type of a value passed to an argument of a `jsonschema` function (like `validate` or `Draft7Validator`) does not match the expected type defined in the `types-jsonschema` stubs.
fix
Ensure the argument's type matches the expected type in the stub; this might involve subclassing `jsonschema.protocols.Validator` for custom validators or providing correctly typed arguments.
Upgrade
Version history
4.26.0.20260408latest on PyPI · released Apr 8, 2026
Audit
Dependencies
jsonschemaoptionalProvides type hints for this runtime library; must be installed separately to use its functionality.
Agent activity
21 hits · last 30 days
node
18
OpenAI (training)
1
Resources
types-jsonschema — pip install types-jsonschema · libregistry