Type stubs for jsonschema JSON Schema validation library
npx @tessl/cli install tessl/pypi-types-jsonschema@3.2.00
# types-jsonschema
1
2
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.
3
4
## Package Information
5
6
- **Package Name**: types-jsonschema
7
- **Package Type**: pypi
8
- **Language**: Python
9
- **Installation**: `pip install types-jsonschema`
10
- **Runtime Dependency**: `pip install jsonschema` (required for actual functionality)
11
12
## Core Imports
13
14
```python
15
import jsonschema
16
```
17
18
Common imports for validation:
19
20
```python
21
from jsonschema import validate, ValidationError, Draft7Validator
22
```
23
24
Comprehensive imports:
25
26
```python
27
from jsonschema import (
28
validate,
29
Draft3Validator, Draft4Validator, Draft6Validator, Draft7Validator,
30
ValidationError, SchemaError, RefResolutionError, FormatError,
31
FormatChecker, TypeChecker,
32
RefResolver
33
)
34
```
35
36
## Basic Usage
37
38
```python
39
import jsonschema
40
from jsonschema import validate, ValidationError
41
42
# Define a JSON schema
43
schema = {
44
"type": "object",
45
"properties": {
46
"name": {"type": "string"},
47
"age": {"type": "number", "minimum": 0}
48
},
49
"required": ["name", "age"]
50
}
51
52
# Valid data
53
data = {"name": "John Doe", "age": 30}
54
55
try:
56
# Validate data against schema
57
validate(instance=data, schema=schema)
58
print("Data is valid!")
59
except ValidationError as e:
60
print(f"Validation error: {e.message}")
61
62
# Using a specific validator
63
from jsonschema import Draft7Validator
64
65
validator = Draft7Validator(schema)
66
if validator.is_valid(data):
67
print("Data is valid!")
68
else:
69
for error in validator.iter_errors(data):
70
print(f"Error: {error.message}")
71
```
72
73
## Architecture
74
75
The jsonschema library follows a modular architecture:
76
77
- **Validators**: Core validation classes for different JSON Schema draft versions
78
- **RefResolver**: Reference resolution system for handling schema references ($ref)
79
- **Format Validation**: Extensible format checking system for string formats
80
- **Type Checking**: Type validation system with customizable type checkers
81
- **Error Reporting**: Comprehensive error reporting with detailed validation failure information
82
83
## Capabilities
84
85
### JSON Schema Validation
86
87
Core validation functionality including validator classes for different JSON Schema drafts, validation functions, and reference resolution.
88
89
```python { .api }
90
def validate(instance: Any, schema: dict, cls: type | None = None, *args, **kwargs) -> None: ...
91
92
class Draft3Validator: ...
93
class Draft4Validator: ...
94
class Draft6Validator: ...
95
class Draft7Validator: ...
96
97
class RefResolver:
98
def __init__(self, base_uri: str, referrer: dict, **kwargs) -> None: ...
99
def resolve(self, ref: str) -> tuple: ...
100
```
101
102
[JSON Schema Validation](./validators.md)
103
104
### Format Validation
105
106
String format validation system with built-in format checkers for common data formats like email, URI, date/time, and custom format registration.
107
108
```python { .api }
109
class FormatChecker:
110
def __init__(self, formats: Iterable[str] | None = None) -> None: ...
111
def check(self, instance: Any, format: str) -> None: ...
112
def conforms(self, instance: Any, format: str) -> bool: ...
113
114
# Pre-configured format checkers
115
draft3_format_checker: FormatChecker
116
draft4_format_checker: FormatChecker
117
draft6_format_checker: FormatChecker
118
draft7_format_checker: FormatChecker
119
```
120
121
[Format Validation](./format-checker.md)
122
123
### Error Handling
124
125
Comprehensive exception hierarchy and error tree structures for detailed validation failure reporting and error analysis.
126
127
```python { .api }
128
class ValidationError(Exception):
129
message: str
130
path: Sequence[str | int]
131
schema_path: Sequence[str]
132
instance: Any
133
schema: dict
134
135
class SchemaError(Exception): ...
136
class RefResolutionError(Exception): ...
137
class FormatError(Exception): ...
138
139
class ErrorTree:
140
def __getitem__(self, index: str | int) -> ErrorTree: ...
141
def __len__(self) -> int: ...
142
@property
143
def total_errors(self) -> int: ...
144
```
145
146
[Error Handling](./exceptions.md)
147
148
### Utilities and Type Checking
149
150
Utility classes, helper functions, and type validation system including custom type checkers and internal utilities.
151
152
```python { .api }
153
class TypeChecker:
154
def __init__(self, type_checkers: dict | None = None) -> None: ...
155
def is_type(self, instance: Any, type: str) -> bool: ...
156
def redefine(self, type: str, fn: Callable) -> TypeChecker: ...
157
158
# Pre-configured type checkers
159
draft3_type_checker: TypeChecker
160
draft4_type_checker: TypeChecker
161
draft6_type_checker: TypeChecker
162
draft7_type_checker: TypeChecker
163
```
164
165
[Utilities and Type Checking](./utilities.md)
166
167
## Types
168
169
```python { .api }
170
from typing import Any, Callable, Iterable, Sequence
171
```
172
173
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.