{"id":395,"library":"fastjsonschema","title":"Fast JSON Schema Validator for Python","description":"A high-performance JSON schema validator for Python, currently at version 2.21.2, with a release cadence of approximately one release per year.","status":"active","version":"2.21.2","language":"python","source_language":"en","source_url":"https://github.com/horejsek/python-fastjsonschema","tags":["JSON Schema","Validation","Performance"],"install":[{"cmd":"pip install fastjsonschema","lang":"bash","label":"Install fastjsonschema"}],"dependencies":[{"reason":"Required for JSON schema validation","package":"jsonschema","optional":false}],"imports":[{"note":"Ensure to import 'compile' from 'fastjsonschema' for schema compilation.","symbol":"compile","correct":"from fastjsonschema import compile"}],"quickstart":{"code":"import os\nimport fastjsonschema\n\n# Define your JSON schema\nschema = {\n    'type': 'object',\n    'properties': {\n        'name': {'type': 'string'},\n        'age': {'type': 'integer'}\n    },\n    'required': ['name', 'age']\n}\n\n# Compile the schema\nvalidate = fastjsonschema.compile(schema)\n\n# Validate data\ndata = {'name': 'John Doe', 'age': 30}\ntry:\n    validate(data)\n    print('Data is valid')\nexcept fastjsonschema.exceptions.JsonSchemaException as e:\n    print(f'Validation error: {e.message}')","lang":"python","description":"A simple example demonstrating how to define a JSON schema, compile it using 'fastjsonschema', and validate data against it."},"warnings":[{"fix":"Update import statements to 'from fastjsonschema import compile'.","message":"In version 2.21.2, the 'compile' function was moved from 'fastjsonschema.schema' to 'fastjsonschema'.","severity":"breaking","affected_versions":"2.21.2"},{"fix":"Install 'jsonschema' using 'pip install jsonschema'.","message":"Ensure that the 'jsonschema' package is installed, as 'fastjsonschema' depends on it for schema validation.","severity":"gotcha","affected_versions":"all"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-12T13:30:16.482Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Install the package using pip: `pip install fastjsonschema`","cause":"The `fastjsonschema` package has not been installed in the Python environment.","error":"ModuleNotFoundError: No module named 'fastjsonschema'"},{"fix":"Update the import statement to directly import `compile` from `fastjsonschema`: `from fastjsonschema import compile`","cause":"In `fastjsonschema` version 2.21.2, the `compile` function was moved from the `fastjsonschema.schema` module directly into the `fastjsonschema` package.","error":"ImportError: cannot import name 'compile' from 'fastjsonschema.schema'"},{"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)`","cause":"This error occurs when a JSON schema is passed as a string to `fastjsonschema.compile()` instead of a parsed Python dictionary.","error":"TypeError: string indices must be integers"},{"fix":"Install the `jsonschema` package: `pip install jsonschema`","cause":"While `fastjsonschema` is a high-performance validator, it relies on the `jsonschema` package for certain functionalities, and this error indicates `jsonschema` is not installed.","error":"ModuleNotFoundError: No module named 'jsonschema'"},{"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.","cause":"This exception is raised when the input data fails validation against the compiled JSON schema.","error":"fastjsonschema.exceptions.JsonSchemaValueException: data.property must be [type] (e.g., 'data.name must be string')"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1.2,"disk_size":"18.0M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":1.2,"disk_size":"18M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.2,"disk_size":"19.8M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.2,"disk_size":"20M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1,"disk_size":"11.7M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1,"disk_size":"12M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.2,"disk_size":"11.3M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1.1,"disk_size":"17.5M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1.1,"disk_size":"18M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}