Pydantic to HTML Converter

0.2.0 · active · verified Thu Apr 16

A Python library designed to automatically convert Pydantic models into structured HTML. It intelligently infers appropriate HTML elements and structures based on the Pydantic model's field types, offering support for nested models, lists, and automatic form generation. The library, currently at version 0.2.0, provides features for customizable themes and optional HTMX integration for interactive forms.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a Pydantic model (including nested models), instantiate it with data, and then convert it into an editable HTML form using `render_html`. The `theme` parameter is used to apply basic styling (e.g., 'bootstrap').

from pydantic import BaseModel
from pydantic_to_html import render_html

class Address(BaseModel):
    street: str
    city: str
    zip_code: str

class User(BaseModel):
    name: str
    email: str
    age: int
    is_active: bool = True
    address: Address

user_data = User(
    name="Jane Doe",
    email="jane.doe@example.com",
    age=29,
    address=Address(street="123 Main St", city="Anytown", zip_code="12345")
)

html_output = render_html(user_data, editable=True, theme="bootstrap")
print(html_output)

view raw JSON →