Skip to main content

Parsdantic is a powerful Python package that automatically generates Pydantic models from JSON schemas.

Project description

Parsdantic

Parsdantic is a powerful Python package that automatically generates Pydantic models from JSON schemas. It simplifies the process of data validation and serialization by bridging the gap between JSON Schema and Pydantic. Features

Features

  • Convert JSON schemas to Pydantic models with a single function call
  • Support for nested objects and complex data structures
  • Automatic type inference and validation

Installation

You can install Parsdantic using pip:

pip install parsdantic

Quick Start

Here's a simple example of how to use Parsdantic:

from parsdantic.parser import parse

schema = {
    "$defs": {
        "Color": {
            "properties": {
                "r": {"title": "R", "type": "integer"},
                "g": {"title": "G", "type": "integer"},
                "b": {"title": "B", "type": "integer"},
            },
            "required": ["r", "g", "b"],
            "title": "Color",
            "type": "object",
        },
        "Hair": {
            "properties": {"color": {"$ref": "#/$defs/Color"}},
            "required": ["color"],
            "title": "Hair",
            "type": "object",
        },
    },
    "properties": {
        "name": {"title": "Name", "type": "string"},
        "age": {"title": "Age", "type": "integer"},
        "hair": {"$ref": "#/$defs/Hair"},
    },
    "required": ["name", "age", "hair"],
    "title": "Person",
    "type": "object",
}

Person = parse(schema)

person = Person(
    name="John",
    age=30,
    hair={"color": {"r": 255, "g": 0, "b": 0}},
)

print(person) # Person(name='John', age=30, hair=Hair(color=Color(r=255, g=0, b=0)))

Note : Collections (e.g. List, Dict) and Enum are still not available.

Support

You can open an issue on the GitHub issue tracker.

LICENSE

This project is licensed under the MIT License. See the LICENSE file 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

parsdantic-0.1.4.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

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

parsdantic-0.1.4-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file parsdantic-0.1.4.tar.gz.

File metadata

  • Download URL: parsdantic-0.1.4.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.21

File hashes

Hashes for parsdantic-0.1.4.tar.gz
Algorithm Hash digest
SHA256 149305decea33b351952a1ebe66d73f4b3ca8b88fb130707dec8bca69358aa96
MD5 6f2c94d04a126b92bd05a47d71b8c0c4
BLAKE2b-256 457a41ccab9f05128451e92a8f9fd2890daef3c0518d5f8e426c914c4ffb75c1

See more details on using hashes here.

File details

Details for the file parsdantic-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: parsdantic-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.21

File hashes

Hashes for parsdantic-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 450fbe69d45d03a169e5850e241f0ea831346d660f6b6f7125cb8849edbba1e1
MD5 3d0f91a42ecede5533f01513d7ddb6a5
BLAKE2b-256 ae4d41862bec7461ee8c0a7ce4a12e29dcb49e68f23b1c3b9bb9227cde58f66f

See more details on using hashes here.

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