{"id":8474,"library":"pydantic-to-html","title":"Pydantic to HTML Converter","description":"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.","status":"active","version":"0.2.0","language":"en","source_language":"en","source_url":"https://github.com/yudame/pydantic-to-html","tags":["pydantic","html","forms","data-conversion","web"],"install":[{"cmd":"pip install pydantic-to-html","lang":"bash","label":"Install pydantic-to-html"}],"dependencies":[{"reason":"Core dependency for defining models to be converted to HTML. Requires Pydantic v2 or newer.","package":"pydantic","optional":false}],"imports":[{"symbol":"render_html","correct":"from pydantic_to_html import render_html"},{"symbol":"BaseModel","correct":"from pydantic import BaseModel"}],"quickstart":{"code":"from pydantic import BaseModel\nfrom pydantic_to_html import render_html\n\nclass Address(BaseModel):\n    street: str\n    city: str\n    zip_code: str\n\nclass User(BaseModel):\n    name: str\n    email: str\n    age: int\n    is_active: bool = True\n    address: Address\n\nuser_data = User(\n    name=\"Jane Doe\",\n    email=\"jane.doe@example.com\",\n    age=29,\n    address=Address(street=\"123 Main St\", city=\"Anytown\", zip_code=\"12345\")\n)\n\nhtml_output = render_html(user_data, editable=True, theme=\"bootstrap\")\nprint(html_output)","lang":"python","description":"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')."},"warnings":[{"fix":"Ensure your Pydantic models adhere to Pydantic V2 syntax. Use `model_dump()` for dictionary representation, `model_dump_json()` for JSON, and migrate `Config` classes to `model_config` attributes. Consider using the `bump-pydantic` tool for automated migration assistance.","message":"Pydantic V1 to V2 migration introduces significant breaking changes that affect `pydantic-to-html`'s underlying Pydantic models. Key method renames (e.g., `.dict()` to `.model_dump()`, `.json()` to `.model_dump_json()`) and configuration changes (e.g., `Config` class to `model_config` dictionary) are common pitfalls.","severity":"breaking","affected_versions":"Pydantic <2.0.0 (when migrating to >=2.0.0)"},{"fix":"For stricter validation, consider using Pydantic's `strict` mode (`model_config = {'strict': True}`) or specific Pydantic types like `StrictStr`, `StrictInt`. Always validate input data against your model's expectations.","message":"Pydantic's default behavior for type coercion can sometimes lead to unexpected data conversions (e.g., a string '10' being coerced to an integer 10). While convenient, it can mask underlying data issues if not explicitly handled or if strict validation is desired.","severity":"gotcha","affected_versions":"All versions of `pydantic-to-html` (due to Pydantic's behavior)"},{"fix":"When catching `ValidationError`, iterate through `exc.errors()` to inspect each individual error. Pay close attention to the `loc` field to pinpoint the exact problematic field in your model. Pydantic's documentation on error handling provides detailed explanations of error types and structures.","message":"Debugging `ValidationError` exceptions from Pydantic models can be challenging due to their detailed, nested structure. Misinterpreting the `loc`, `msg`, and `type` fields in the error details can lead to incorrect fixes.","severity":"gotcha","affected_versions":"All versions of `pydantic-to-html` (due to Pydantic's behavior)"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Replace `.dict()` with `.model_dump()` and `.json()` with `.model_dump_json()` for Pydantic V2 models.","cause":"This error occurs when using Pydantic V2 or newer models with methods deprecated in V1, such as `.dict()` or `.json()`.","error":"AttributeError: 'BaseModel' object has no attribute 'dict'"},{"fix":"Ensure that the data provided for integer fields is either an actual integer or a string that can be successfully converted to an integer by Pydantic. Review the input data for the indicated field and correct its type or value.","cause":"Input data for a field specified as an integer (e.g., `age: int`) contains a non-integer value that Pydantic cannot coerce, such as a string that doesn't represent a number, or a boolean.","error":"pydantic. ValidationError: 1 validation error for [YourModelName] [field name] value is not a valid integer (type=type_error.integer)"},{"fix":"Provide a value for the required field. If the field should be optional, define it using `Optional[Type]` (e.g., `field: Optional[str]`) or provide a default value (e.g., `field: str = 'default_value'`).","cause":"A required field in your Pydantic model was not provided in the input data, or was explicitly set to `None` without being marked as `Optional` or having a default value.","error":"pydantic. ValidationError: 1 validation error for [YourModelName] [field name] field required"}]}