Dydantic

0.0.8 · active · verified Sun Apr 12

Dydantic is a Python library designed for dynamically generating Pydantic models directly from JSON Schema definitions. It offers a streamlined approach to creating Pydantic models on-the-fly, based on user-defined schemas, and is currently at version 0.0.8. The project appears to be actively maintained, with a recent PyPI release and GitHub activity.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a simple JSON schema and use `dydantic` to create a corresponding Pydantic model. It then shows how to instantiate and serialize the dynamically generated model.

from dydantic import create_model_from_schema

json_schema = {
    "title": "Person",
    "type": "object",
    "properties": {
        "name": {"type": "string"},
        "age": {"type": "integer"}
    },
    "required": ["name"]
}

Person = create_model_from_schema(json_schema)
person_instance = Person(name="Jane Doe", age=30)

print(person_instance.model_dump_json(indent=2))
# Expected output:
# {
#   "name": "Jane Doe",
#   "age": 30
# }

view raw JSON →