Install & Compatibility
Where this runs
tested against v2.22.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.026s · 18MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.7s · import 0.022s · 19MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
compile
✓ from fastjsonschema import compile
Ensure to import 'compile' from 'fastjsonschema' for schema compilation.
A simple example demonstrating how to define a JSON schema, compile it using 'fastjsonschema', and validate data against it.
import os
import fastjsonschema
# Define your JSON schema
schema = {
'type': 'object',
'properties': {
'name': {'type': 'string'},
'age': {'type': 'integer'}
},
'required': ['name', 'age']
}
# Compile the schema
validate = fastjsonschema.compile(schema)
# Validate data
data = {'name': 'John Doe', 'age': 30}
try:
validate(data)
print('Data is valid')
except fastjsonschema.exceptions.JsonSchemaException as e:
print(f'Validation error: {e.message}')
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'fastjsonschema'
The `fastjsonschema` package has not been installed in the Python environment.
fixInstall the package using pip: `pip install fastjsonschema`
ImportError: cannot import name 'compile' from 'fastjsonschema.schema'
In `fastjsonschema` version 2.21.2, the `compile` function was moved from the `fastjsonschema.schema` module directly into the `fastjsonschema` package.
fixUpdate the import statement to directly import `compile` from `fastjsonschema`: `from fastjsonschema import compile`
TypeError: string indices must be integers
This error occurs when a JSON schema is passed as a string to `fastjsonschema.compile()` instead of a parsed Python dictionary.
fixEnsure the JSON schema is parsed into a Python dictionary using `json.loads()` before passing it to `fastjsonschema.compile()`: `import json; schema_dict = json.loads(schema_string); validate = fastjsonschema.compile(schema_dict)`
ModuleNotFoundError: No module named 'jsonschema'
While `fastjsonschema` is a high-performance validator, it relies on the `jsonschema` package for certain functionalities, and this error indicates `jsonschema` is not installed.
fixInstall the `jsonschema` package: `pip install jsonschema`
fastjsonschema.exceptions.JsonSchemaValueException: data.property must be [type] (e.g., 'data.name must be string')
This exception is raised when the input data fails validation against the compiled JSON schema.
fixInspect the error message (`e.message`), `e.path`, and `e.value` properties of the `JsonSchemaValueException` to understand which part of the data violates the schema, then modify the data to conform to the schema or adjust the schema definition.
Upgrade
Version history
2.22.2latest on PyPI · released Aug 15, 2026
Audit
Dependencies
jsonschemarequiredRequired for JSON schema validation