or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

exceptions.mdformat-checker.mdindex.mdutilities.mdvalidators.md
tile.json

tessl/pypi-types-jsonschema

Type stubs for jsonschema JSON Schema validation library

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/types-jsonschema@3.2.x

To install, run

npx @tessl/cli install tessl/pypi-types-jsonschema@3.2.0

index.mddocs/

types-jsonschema

Type 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.

Package Information

  • Package Name: types-jsonschema
  • Package Type: pypi
  • Language: Python
  • Installation: pip install types-jsonschema
  • Runtime Dependency: pip install jsonschema (required for actual functionality)

Core Imports

import jsonschema

Common imports for validation:

from jsonschema import validate, ValidationError, Draft7Validator

Comprehensive imports:

from jsonschema import (
    validate,
    Draft3Validator, Draft4Validator, Draft6Validator, Draft7Validator,
    ValidationError, SchemaError, RefResolutionError, FormatError,
    FormatChecker, TypeChecker,
    RefResolver
)

Basic Usage

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}")

Architecture

The jsonschema library follows a modular architecture:

  • Validators: Core validation classes for different JSON Schema draft versions
  • RefResolver: Reference resolution system for handling schema references ($ref)
  • Format Validation: Extensible format checking system for string formats
  • Type Checking: Type validation system with customizable type checkers
  • Error Reporting: Comprehensive error reporting with detailed validation failure information

Capabilities

JSON Schema Validation

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: ...

JSON Schema Validation

Format Validation

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: FormatChecker

Format Validation

Error Handling

Comprehensive 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: ...

Error Handling

Utilities and Type Checking

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: TypeChecker

Utilities and Type Checking

Types

from typing import Any, Callable, Iterable, Sequence

Note: 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.