JSON Schema to Pydantic model conversion library
Project description
Pydantic JSON Schema
Pydantic turns models into JSON Schema. This library does the reverse — it turns a JSON Schema into a Pydantic model, so you can validate data against a schema you already have, with all of Pydantic's runtime checks and editor support.
Reach for it when the schema comes first: API contracts, config files, tool definitions, or validating LLM output against a fixed shape.
Installation
uv add pydantic-jsonschema
Requires Python 3.12+. See the installation guide for optional 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}
What's inside
Three building blocks — and a fourth on the way.
1. The schema model — Schema & Reference
A Pydantic model for JSON Schema itself: parse, inspect, and serialize schemas with full
type safety. $refs are parsed as Reference objects and resolved during conversion.
from pydantic_jsonschema import DataType, Schema
schema = Schema(
type=DataType.OBJECT,
properties={"name": Schema(type=DataType.STRING)},
required=["name"],
)
print(schema.model_dump_json())
#> {"type":"object","properties":{"name":{"type":"string"}},"required":["name"]}
2. The converter — to_model / SchemaConverter
Turns a Schema into a Pydantic model (see Quick start). It resolves
$ref / $defs, maps anyOf / oneOf (including discriminated unions) / allOf to
Python types, and applies string, number, array, and object constraints as Pydantic
validation.
3. Formats
Built-in validators for every format in the JSON Schema spec (email, uri, uuid,
date-time, hostname, json-pointer, regex, and more) — with zero extra
dependencies. Pass your own callable for custom formats.
from pydantic_jsonschema import Schema, to_model
from pydantic_jsonschema.formats import Email
schema = Schema.model_validate({
"type": "object",
"properties": {"email": {"type": "string", "format": "email"}},
"required": ["email"],
})
User = to_model(schema, formats={"email": Email})
print(User(email="alice@example.com").email)
#> alice@example.com
Planned: configurable loading by type
Per-object control over how each type is loaded, inspired by adaptix.
Documentation
https://danipulok.github.io/pydantic-jsonschema/
Acknowledgments
License
MIT License - see LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydantic_jsonschema-0.0.12.tar.gz.
File metadata
- Download URL: pydantic_jsonschema-0.0.12.tar.gz
- Upload date:
- Size: 37.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7fa704d6a722e5c30363ad692718eba67007424de14cfb72100f6c9630389221
|
|
| MD5 |
075fe74035006ce926e1e09ab5a96aa6
|
|
| BLAKE2b-256 |
15789e62dd94e0596e28c4d6b705b817678912cbac1f65fc32dfd0eaaab99f32
|
Provenance
The following attestation bundles were made for pydantic_jsonschema-0.0.12.tar.gz:
Publisher:
release.yml on Danipulok/pydantic-jsonschema
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic_jsonschema-0.0.12.tar.gz -
Subject digest:
7fa704d6a722e5c30363ad692718eba67007424de14cfb72100f6c9630389221 - Sigstore transparency entry: 1925847915
- Sigstore integration time:
-
Permalink:
Danipulok/pydantic-jsonschema@72caae10a5cefdf4c55548deb98614e590513ec9 -
Branch / Tag:
refs/tags/v0.0.12 - Owner: https://github.com/Danipulok
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@72caae10a5cefdf4c55548deb98614e590513ec9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pydantic_jsonschema-0.0.12-py3-none-any.whl.
File metadata
- Download URL: pydantic_jsonschema-0.0.12-py3-none-any.whl
- Upload date:
- Size: 53.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a156f1e8df5163bda421371b17182013074f131cf5b08754b784d955fa0485c9
|
|
| MD5 |
bfd610d242b4441aeafe9a5131e55e17
|
|
| BLAKE2b-256 |
5e244eb2e180c4f5aba2d939c492d811d5590afc2d7a8dd123eadb1d1d907494
|
Provenance
The following attestation bundles were made for pydantic_jsonschema-0.0.12-py3-none-any.whl:
Publisher:
release.yml on Danipulok/pydantic-jsonschema
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic_jsonschema-0.0.12-py3-none-any.whl -
Subject digest:
a156f1e8df5163bda421371b17182013074f131cf5b08754b784d955fa0485c9 - Sigstore transparency entry: 1925848037
- Sigstore integration time:
-
Permalink:
Danipulok/pydantic-jsonschema@72caae10a5cefdf4c55548deb98614e590513ec9 -
Branch / Tag:
refs/tags/v0.0.12 - Owner: https://github.com/Danipulok
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@72caae10a5cefdf4c55548deb98614e590513ec9 -
Trigger Event:
push
-
Statement type: