JSON Schema to Pydantic model conversion library
Project description
Pydantic JSON Schema
Convert JSON Schema definitions into Pydantic models with runtime validation.
Installation
uv add pydantic-jsonschema
Requires Python 3.12+. See the installation guide for optional format validator extras.
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-pydanticdependency) - Zero-dependency format validation (remove
uri-format,iri-formatdependencies) - Logic fixes in schema conversion
- Add
inline_snapshotfor 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
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.2.tar.gz.
File metadata
- Download URL: pydantic_jsonschema-0.0.2.tar.gz
- Upload date:
- Size: 13.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf9ffd961654656ce9bb0b4ff0f42a9b5b7ff2db5944895c7d437223ca20393a
|
|
| MD5 |
84a78391d6641e168a5e3b7d42f7c5f7
|
|
| BLAKE2b-256 |
3775586153559eae47288d0c42e95647cee40c195c47e13f8f4d2701043dd17f
|
Provenance
The following attestation bundles were made for pydantic_jsonschema-0.0.2.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.2.tar.gz -
Subject digest:
cf9ffd961654656ce9bb0b4ff0f42a9b5b7ff2db5944895c7d437223ca20393a - Sigstore transparency entry: 1794078266
- Sigstore integration time:
-
Permalink:
Danipulok/pydantic-jsonschema@c0a1dc69a87173055955a4169489606760d22c2b -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/Danipulok
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c0a1dc69a87173055955a4169489606760d22c2b -
Trigger Event:
push
-
Statement type:
File details
Details for the file pydantic_jsonschema-0.0.2-py3-none-any.whl.
File metadata
- Download URL: pydantic_jsonschema-0.0.2-py3-none-any.whl
- Upload date:
- Size: 15.8 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 |
d984a18bb997d52ce8d64c5012f15fb63173b4b8a81f56bd4e2e9ec5dac9d93f
|
|
| MD5 |
705b7d1f4c867f954fbbb29e3f333a51
|
|
| BLAKE2b-256 |
48a51975645c0efede1d22462d2e55fa6b0bdf7d6427ed4dd4a8fe34cdc5b708
|
Provenance
The following attestation bundles were made for pydantic_jsonschema-0.0.2-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.2-py3-none-any.whl -
Subject digest:
d984a18bb997d52ce8d64c5012f15fb63173b4b8a81f56bd4e2e9ec5dac9d93f - Sigstore transparency entry: 1794078456
- Sigstore integration time:
-
Permalink:
Danipulok/pydantic-jsonschema@c0a1dc69a87173055955a4169489606760d22c2b -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/Danipulok
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c0a1dc69a87173055955a4169489606760d22c2b -
Trigger Event:
push
-
Statement type: