Skip to main content

Automatically generate Pydantic models from dictionaries

Project description

PyAutoSchema

PyAutoSchema is a lightweight Python library that automatically generates Pydantic models from Python dictionaries, JSON, or XML files. It's especially useful for fast prototyping, validating API responses, or converting JSON-like structures into Pydantic schemas.

🔧 Features

  • Supports nested dictionaries and complex data structures
  • Infers list, union, and other advanced types
  • Generates clean, human-readable Pydantic classes
  • Supports JSON and XML input formats
  • Simple one-line usage

📦 Installation

Install PyAutoSchema using pip:

pip install pyautoschema

🚀 Usage

Python Dictionary Example

from pyautoschema import schemaCreator

sample = {
    "id": 123,
    "name": "Alice",
    "tags": ["admin", "user"],
    "profile": {
        "age": 30,
        "active": True
    }
}

infer_schema(sample, output="schemas.py")

Generated output (schemas.py):

from typing import List
from pydantic import BaseModel

class Profile(BaseModel):
    age: int
    active: bool

class InferredModel(BaseModel):
    id: int
    name: str
    tags: List[str]
    profile: Profile

JSON File Example

pyautoschema --input sample.json --output schemas.py

XML File Example

pyautoschema --input sample.xml --output schemas.py

🛠 CLI Usage

PyAutoSchema also provides a command-line interface for generating schemas directly from JSON or XML files.

pyautoschema --input <path_to_file> --output <output_file>
  • --input (-i): Path to the input .json or .xml file (required)
  • --output (-o): Path to the output .py file (default: schemas.py)

🧪 Supported Types

PyAutoSchema automatically detects and maps the following types:

  • Primitive Types: int, float, bool, str
  • Advanced Types: datetime, date, time, UUID, EmailStr, HttpUrl
  • Collections: List, Union, Any

🌐 Links

📄 License

This project is licensed under the terms of 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

pyautoschema-0.2.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

pyautoschema-0.2.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file pyautoschema-0.2.0.tar.gz.

File metadata

  • Download URL: pyautoschema-0.2.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for pyautoschema-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c9b79ea5c7ecc5330cc9543d2582481943e6bb1152151efcb8d69e6e242e3656
MD5 b658befbb383c85142701db430fa8212
BLAKE2b-256 de0459d0d6fc96929c39d657803720335a0080854adf4b5e1105b2c26c1a6be0

See more details on using hashes here.

File details

Details for the file pyautoschema-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pyautoschema-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for pyautoschema-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 22250433641a08ec327e595c9df4446c7657b37005454757d8c65e6809c22af3
MD5 93fb323de30473c048b0c4d62eaf0cf4
BLAKE2b-256 9d1ef6812d2b226c6a144a94d531ffc715988c4384e1c7a704c513385337077d

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