{"id":2913,"library":"dash-pydantic-form","title":"Dash Pydantic Form","description":"Dash-pydantic-form is a Python library that enables rapid creation of interactive forms within Plotly Dash applications, powered by Pydantic models. It leverages dash-mantine-components (DMC) for a rich set of input fields and seamlessly handles complex data structures like nested models and lists. The library is actively maintained, with frequent minor and patch releases, and is currently at version 0.18.3.","status":"active","version":"0.18.3","language":"en","source_language":"en","source_url":"https://github.com/RenaudLN/dash-pydantic-form","tags":["Dash","Pydantic","forms","UI","web development","data validation"],"install":[{"cmd":"pip install dash-pydantic-form","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Requires Pydantic V2 for model definition and validation.","package":"pydantic","optional":false},{"reason":"Core dependency for building Dash applications.","package":"dash","optional":false},{"reason":"Used for rendering the underlying UI components of the form.","package":"dash-mantine-components","optional":false}],"imports":[{"symbol":"ModelForm","correct":"from dash_pydantic_form import ModelForm"},{"symbol":"BaseModel, Field","correct":"from pydantic import BaseModel, Field"},{"note":"While `import dash` works, it's common practice and often more explicit to import specific components and functions directly, especially `Dash`, `html`, `callback`, `Input`, and `Output` for application and callback definition. The library itself switched to wildcard imports for `dash` in 0.18.3, but direct imports are still recommended for user applications.","wrong":"import dash","symbol":"Dash, html, callback, Input, Output","correct":"from dash import Dash, html, callback, Input, Output"}],"quickstart":{"code":"import os\nfrom datetime import date\nfrom typing import Literal\n\nfrom dash import Dash, html, callback, Input, Output\nfrom dash_pydantic_form import ModelForm\nfrom pydantic import BaseModel, Field, ValidationError\n\n# Define a Pydantic model\nclass Employee(BaseModel):\n    first_name: str = Field(title=\"First name\")\n    last_name: str = Field(title=\"Last name\")\n    office: Literal[\"au\", \"uk\", \"us\", \"fr\"] = Field(title=\"Office\")\n    joined: date = Field(title=\"Employment date\")\n\n# Initialize the Dash app\napp = Dash(__name__)\n\n# Define the app layout\napp.layout = html.Div([\n    html.H1(\"Employee Form\"),\n    ModelForm(\n        Employee,\n        aio_id=\"employees_form_id\",\n        form_id=\"new_employee_form\"\n    ),\n    html.Div(id=\"form-output\")\n])\n\n# Define a callback to process form data\n@callback(\n    Output(\"form-output\", \"children\"),\n    Input(ModelForm.ids.main(\"employees_form_id\", \"new_employee_form\"), \"data\")\n)\ndef use_form_data(form_data: dict):\n    if form_data is None:\n        return html.Pre(\"Waiting for form data...\")\n    try:\n        employee = Employee(**form_data)\n        return html.Pre(f\"Validated Employee: {employee.model_dump_json(indent=2)}\")\n    except ValidationError as exc:\n        return html.Pre(f\"Validation Error:\\n{exc.errors()}\\nRaw Data: {form_data}\", style={'color': 'red'})\n\nif __name__ == '__main__':\n    app.run(debug=True)","lang":"python","description":"This quickstart demonstrates how to create a basic Dash application with a form generated directly from a Pydantic `BaseModel`. It includes the necessary imports, model definition, `ModelForm` instantiation in the layout, and a callback to capture and validate the submitted form data."},"warnings":[{"fix":"Ensure `pydantic>=2.0.0` is installed in your environment.","message":"The library explicitly requires Pydantic V2. Using Pydantic V1 will lead to incompatibility issues and errors.","severity":"breaking","affected_versions":"<0.1.0 (earlier versions not Pydantic V2 compatible), all versions requiring Pydantic 2+"},{"fix":"Migrate field customizations from `Field(repr_type=..., repr_kwargs=...)` to `Field(json_schema_extra={'repr_type': ..., 'repr_kwargs': ...})`.","message":"Directly passing `repr_type` and `repr_kwargs` to `pydantic.Field` is deprecated. For future compatibility, use `json_schema_extra={'repr_type': ..., 'repr_kwargs': ...}` for customizing input rendering.","severity":"deprecated","affected_versions":"All versions where Pydantic's `Field` `extras` keyword arguments are deprecated, roughly `0.17.x` and above."},{"fix":"Define a `__str__` method on your Pydantic models that are used in list fields to ensure correct initial titles in accordions/modals.","message":"For versions 0.15.0 and above, when using list fields with accordion or modal titles, you might need to define the `__str__` method on your Pydantic models. This is due to performance improvements in `MATCH` callbacks setting `prevent_initial_call`, affecting how initial names are displayed.","severity":"gotcha","affected_versions":"0.15.0 and later."},{"fix":"Adhere to the `(field, operator, value)` tuple format for defining conditional visibility in `Field` arguments (e.g., `Field(visible=('status', '==', 'active'))`).","message":"Conditional field visibility operates client-side and requires a specific 3-tuple format `(field, operator, value)`. Python lambda functions or direct Python logic for visibility conditions are not supported.","severity":"gotcha","affected_versions":"All versions."},{"fix":"Ensure you are using version 0.17.5 or later if you plan to have multiple `ModelForm` instances on the same Dash page.","message":"Earlier versions (prior to 0.17.5) had known issues with multiple `ModelForm` instances on a single page causing update problems. While fixed, it's a complexity to be aware of in large applications.","severity":"gotcha","affected_versions":"<0.17.5"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}