Registry / serialization / fastjsonschema

fastjsonschema

JSON →
library2.22.2pypypi✓ verified 31d ago

A high-performance JSON schema validator for Python, currently at version 2.21.2, with a release cadence of approximately one release per year.

pip install fastjsonschema
INSTALL
IMPORT
SIG · FASTJSONSCHEMA
F
fastjsonschema
serializationpythonv2.22.2
Install
1.7s avg
Import
24ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
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
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.026s · 18MB
glibc
py 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}')
Debug
Known issues
breakingIn version 2.21.2, the 'compile' function was moved from 'fastjsonschema.schema' to 'fastjsonschema'.
fix
Update import statements to 'from fastjsonschema import compile'.
affects: 2.21.2
gotchaEnsure that the 'jsonschema' package is installed, as 'fastjsonschema' depends on it for schema validation.
fix
Install 'jsonschema' using 'pip install jsonschema'.
affects: all
gotchaThe environment reports pip warnings related to running as root or requiring an update. These are not issues with the library's functionality but rather environmental concerns with pip itself.
fix
It is recommended to use a virtual environment or avoid running pip as the 'root' user to prevent permission issues. Consider updating pip to the latest version as suggested by the notice.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'fastjsonschema'
The `fastjsonschema` package has not been installed in the Python environment.
fix
Install 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.
fix
Update 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.
fix
Ensure 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.
fix
Install 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.
fix
Inspect 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
Agent activity
14 hits · last 30 days
node
14
Resources
fastjsonschema — pip install fastjsonschema · libregistry