Skip to content

tillahoffmann/schema2model

Repository files navigation

schema2model

CI PyPI

Convert JSON Schema dictionaries to Pydantic models.

Installation

pip install schema2model

Usage

from schema2model import schema2model

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

User = schema2model(schema)
user = User(name="Alice", age=30)

Supported Features

  • Basic types: str, int, float, bool
  • Collections: list, set, tuple, dict
  • Date/time: datetime, date, time, timedelta
  • Special types: UUID, bytes, AnyHttpUrl
  • Nested models and enums
  • Recursive models
  • RootModel
  • Discriminated unions
  • Field constraints (gt, lt, min_length, pattern, etc.)
  • Field metadata (description, examples, deprecated)

About

Convert JSON schemas to Pydantic models

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages