Type stubs for jsonschema JSON Schema validation library
npx @tessl/cli install tessl/pypi-types-jsonschema@3.2.0Type stubs for the jsonschema library, providing static type checking for JSON Schema validation in Python applications. This package enables developers to use jsonschema with full type safety and IDE support, covering JSON Schema validation for Draft 3, 4, 6, and 7 specifications.
pip install types-jsonschemapip install jsonschema (required for actual functionality)import jsonschemaCommon imports for validation:
from jsonschema import validate, ValidationError, Draft7ValidatorComprehensive imports:
from jsonschema import (
validate,
Draft3Validator, Draft4Validator, Draft6Validator, Draft7Validator,
ValidationError, SchemaError, RefResolutionError, FormatError,
FormatChecker, TypeChecker,
RefResolver
)import jsonschema
from jsonschema import validate, ValidationError
# Define a JSON schema
schema = {
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "number", "minimum": 0}
},
"required": ["name", "age"]
}
# Valid data
data = {"name": "John Doe", "age": 30}
try:
# Validate data against schema
validate(instance=data, schema=schema)
print("Data is valid!")
except ValidationError as e:
print(f"Validation error: {e.message}")
# Using a specific validator
from jsonschema import Draft7Validator
validator = Draft7Validator(schema)
if validator.is_valid(data):
print("Data is valid!")
else:
for error in validator.iter_errors(data):
print(f"Error: {error.message}")The jsonschema library follows a modular architecture:
Core validation functionality including validator classes for different JSON Schema drafts, validation functions, and reference resolution.
def validate(instance: Any, schema: dict, cls: type | None = None, *args, **kwargs) -> None: ...
class Draft3Validator: ...
class Draft4Validator: ...
class Draft6Validator: ...
class Draft7Validator: ...
class RefResolver:
def __init__(self, base_uri: str, referrer: dict, **kwargs) -> None: ...
def resolve(self, ref: str) -> tuple: ...String format validation system with built-in format checkers for common data formats like email, URI, date/time, and custom format registration.
class FormatChecker:
def __init__(self, formats: Iterable[str] | None = None) -> None: ...
def check(self, instance: Any, format: str) -> None: ...
def conforms(self, instance: Any, format: str) -> bool: ...
# Pre-configured format checkers
draft3_format_checker: FormatChecker
draft4_format_checker: FormatChecker
draft6_format_checker: FormatChecker
draft7_format_checker: FormatCheckerComprehensive exception hierarchy and error tree structures for detailed validation failure reporting and error analysis.
class ValidationError(Exception):
message: str
path: Sequence[str | int]
schema_path: Sequence[str]
instance: Any
schema: dict
class SchemaError(Exception): ...
class RefResolutionError(Exception): ...
class FormatError(Exception): ...
class ErrorTree:
def __getitem__(self, index: str | int) -> ErrorTree: ...
def __len__(self) -> int: ...
@property
def total_errors(self) -> int: ...Utility classes, helper functions, and type validation system including custom type checkers and internal utilities.
class TypeChecker:
def __init__(self, type_checkers: dict | None = None) -> None: ...
def is_type(self, instance: Any, type: str) -> bool: ...
def redefine(self, type: str, fn: Callable) -> TypeChecker: ...
# Pre-configured type checkers
draft3_type_checker: TypeChecker
draft4_type_checker: TypeChecker
draft6_type_checker: TypeChecker
draft7_type_checker: TypeCheckerfrom typing import Any, Callable, Iterable, SequenceNote: Many parameters and return values use Any type as JSON Schema validation works with arbitrary JSON data structures. The jsonschema library is designed to be flexible with dynamic data types.