Skip to main content

JSON Schema to Pydantic model conversion library

Project description

Pydantic JSON Schema

CI Coverage PyPI Python Versions License: MIT Docs Ruff uv mypy pre-commit

Convert JSON Schema definitions into Pydantic models with runtime validation.

Installation

uv add pydantic-jsonschema

Requires Python 3.12+. See the installation guide for third-party validator libraries.

Quick Start

from pydantic_jsonschema import Schema, to_model

schema = Schema.model_validate({
    "type": "object",
    "properties": {
        "name": {"type": "string"},
        "age": {"type": "integer", "minimum": 0},
    },
    "required": ["name"],
})

User = to_model(schema, model_name="User")

user = User(name="Alice", age=30)
print(user.model_dump())
#> {'name': 'Alice', 'age': 30}

Schema Model

The Schema class is a Pydantic model representing a JSON Schema object. Use it to parse, inspect, and serialize schemas with full type safety:

from pydantic_jsonschema import DataType, Schema

schema = Schema(
    type=DataType.OBJECT,
    properties={
        "name": Schema(type=DataType.STRING),
    },
    required=["name"],
)

print(schema.model_dump_json(indent=4))
"""
{
    "type": "object",
    "properties": {
        "name": {
            "type": "string"
        }
    },
    "required": [
        "name"
    ]
}
"""

Schema supports $ref and $defs for reusable definitions — properties referencing a $ref are parsed as Reference objects and resolved automatically during conversion.

See the Schema documentation for field reference and usage examples.

Documentation

https://danipulok.github.io/pydantic-jsonschema/

Roadmap

  • Custom JSON Schema implementation (remove openapi-pydantic dependency)
  • Remove fqdn and rfc3986 dependencies
  • Remove email-validator dependency
  • Logic fixes in schema conversion
  • Add inline_snapshot for tests
  • Configurable loading by type (inspired by adaptix)

Acknowledgments

  • vgavro — initial library idea, guidance, and ongoing support
  • bodlan — contributions to documentation and conversion logic

License

MIT License - see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydantic_jsonschema-0.0.8.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydantic_jsonschema-0.0.8-py3-none-any.whl (21.7 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_jsonschema-0.0.8.tar.gz.

File metadata

  • Download URL: pydantic_jsonschema-0.0.8.tar.gz
  • Upload date:
  • Size: 18.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pydantic_jsonschema-0.0.8.tar.gz
Algorithm Hash digest
SHA256 afd6ec2a031fdba7d540eb863628a77c9c4bc59604e145f07c715a6369b6436a
MD5 2f5223e5c036367fd1078bf8d17a03ce
BLAKE2b-256 3bb1fab9e4fd73092e23e812b9b87f2a13f8b3e7653a01c2852869f0b2433429

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydantic_jsonschema-0.0.8.tar.gz:

Publisher: release.yml on Danipulok/pydantic-jsonschema

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pydantic_jsonschema-0.0.8-py3-none-any.whl.

File metadata

File hashes

Hashes for pydantic_jsonschema-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 fb13d2c3fea8da2c16f349deda306c6e976f378294a9bd98258d5d9b4b034354
MD5 9f2802cdbe0c6b2d2b1d0b79ffaf3aa4
BLAKE2b-256 26a8fc7f8d0ac14d23c3e6105c66211e510cc476ba0dcc2e6d02659945e7af67

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydantic_jsonschema-0.0.8-py3-none-any.whl:

Publisher: release.yml on Danipulok/pydantic-jsonschema

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page