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": {
        "Person": {
            "properties": {
                "id": {"title": "Id", "type": "integer"},
                "name": {"title": "Name", "type": "string"},
                "directions": {
                    "items": {"type": "string"},
                    "title": "Directions",
                    "type": "array"
                }
            },
            "required": ["id", "name", "directions"],
            "title": "Person",
            "type": "object"
        }
    },
    "properties": {
        "people": {
            "items": {"$ref": "#/$defs/Person"},
            "title": "People",
            "type": "array"
        }
    },
    "required": ["people"],
    "title": "People",
    "type": "object"
}

People = parse(schema)

instance = People(
    people=[
        {"id": 1, "name": "John", "directions": ["Carrer de les Corts, 1", "Barcelona"]},
        {"id": 2, "name": "Jane", "directions": ["Carrer de les Corts, 2", "Barcelona"]},
    ]
)

print(instance) # People(people=[Person(id=1, name='John', directions=['Carrer de les Corts, 1', 'Barcelona']), Person(id=2, name='Jane', directions=['Carrer de les Corts, 2', 'Barcelona'])])

Note: descriptions, default values, required fields, and Enum types are still not supported.

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.5.tar.gz (27.4 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.5-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for parsdantic-0.1.5.tar.gz
Algorithm Hash digest
SHA256 232d184c7ed3fb29dd61474c50d12f16dca6a8efd2b031d8949675080902dc13
MD5 0aac1db99cb5495f86832bbd76d52727
BLAKE2b-256 acc16aafcda6fbaad9d3543df176b263be3626c6e2a755b77f7fd4e6d3f09771

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for parsdantic-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 0ea0429be4201a28458ee9164e7df376f445e215b10e765a01814de4474cbb32
MD5 49e5709e442c9073d67caf79d330b489
BLAKE2b-256 bb47dc4e306be141cbbdca95959caee1dfd021f0707e7b195b44f9133b40fe96

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