Registry / serialization / pyjsg
library0.12.4pypypi✓ verified 82d ago

pyjsg (Python JSON Schema Grammar interpreter) is a library that allows defining JSON schemas as Python classes and validating data against these generated structures. It provides tools to convert JSON Schema definitions into Python objects, facilitating type-safe data handling and validation within Python applications. The current stable version is 0.12.3, with releases occurring as features and bug fixes are implemented, typically not on a fixed schedule.

pip install pyjsg
INSTALL
IMPORT
SIG · PYJSG
P
pyjsg
serializationpythonv0.12.4
Install
3.1s avg
Import
Disk
22MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.12.4 · 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.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 24.4MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 3.1s · import 0.000s · 25MB
22MB installed
● package 22MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

JSG
import pyjsg
from pyjsg import JSG

This quickstart defines a simple 'Person' JSON Schema using `pyjsg` decorators, creates a validator, and demonstrates validating both valid and invalid data against it. It also shows how to access the validated data as a Python object and dump it back to a dictionary.

from pyjsg.jsg import JSG, JSG_DUMP from pyjsg.validate import JSGValidate # Define a JSON Schema using pyjsg decorators @JSG( jsg_name="Person", jsg_uri="http://example.com/Person.jsg", jsg_description="A simple person schema" ) class Person: name: str age: int isStudent: bool = False # Optional with default # Example data valid_person_data = {"name": "Alice", "age": 30} invalid_person_data = {"name": "Bob", "age": "twenty"} # Create a validator instance validator = JSGValidate(Person) # Validate valid data try: validated_person = validator.validate(valid_person_data) print(f"Valid person: {validated_person}") # Access validated data as a pyjsg object print(f"Name: {validated_person.name}, Age: {validated_person.age}, Is Student: {validated_person.isStudent}") print(f"Dumped valid person: {JSG_DUMP(validated_person)}") except Exception as e: print(f"Validation failed for valid data: {e}") # Validate invalid data try: validator.validate(invalid_person_data) print("Invalid person data somehow passed validation.") except Exception as e: print(f"Validation correctly failed for invalid data: {e}")
Debug
Known issues
gotchapyjsg interprets a subset of JSON Schema. Complex or non-standard JSON Schemas may not translate directly into `pyjsg` Python classes or validate as expected.
fix
Review `pyjsg`'s supported JSON Schema features and adjust your schema accordingly. Consider breaking down complex schemas or using `pyjsg` for the core data structures and a more generic validator for auxiliary constraints.
affects: All versions
breakingAs a 0.x.x library, `pyjsg` may introduce breaking changes in minor versions (e.g., 0.11 to 0.12). API signatures, especially around schema definition and validation, can change.
fix
Always pin `pyjsg` to an exact version in `requirements.txt` (e.g., `pyjsg==0.12.3`). Review release notes carefully when upgrading. Consult the latest documentation for updated API usage.
affects: 0.x.x series
gotcha`pyjsg` generates Python classes from schemas. Direct manipulation of the raw `dict` output from `JSG_DUMP` or `JSG_LOAD` may lose type safety or fail validation if not re-instantiated through `pyjsg` classes.
fix
Work with the `pyjsg` generated Python objects directly when possible. If you need to manipulate raw dictionaries, ensure they conform to the schema and re-validate or re-instantiate through the `pyjsg` class if you intend to continue using `pyjsg`'s type safety.
affects: All versions
Upgrade
Version history
0.12.4latest on PyPI · released May 1, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
12
Resources
pyjsg — pip install pyjsg · libregistry