Skip to main content

Create HTML boilerplate from pydantic models

Project description

Dainty

Dainty is a simple, plug and play extension of pydantic, that allows you to easily create HTML input elements based on your pydantic models.

Installation

uv add dainty

Usage

from typing import Literal

from pydantic import Field

from dainty import DaintyModel
from dainty.dainty import DaintyForm


class MyModel(DaintyModel):
    name: str
    age: int = Field(ge=20, lt=40)
    gender: Literal["Male", "Female", "Non Binary", "Other"]

    dainty_form = DaintyForm(target_url="/submit")


print(MyModel.to_html(form=True))

This will generate the following HTML:

<form>
  <label for="name">Name: </label>
  <input type="text" name="name" id="name" value="" required />
  <br /><br />
  <label for="age">Age: </label>
  <input
    type="number"
    name="age"
    id="age"
    value=""
    step="1"
    min="20"
    max="39"
    required
  />
  <br /><br />
  <label for="gender">Gender: </label>
  <select name="gender" id="gender" required>
    <option value="Male">Male</option>
    <option value="Female">Female</option>
    <option value="Non Binary">Non Binary</option>
    <option value="Other">Other</option>
  </select>
  <br /><br />
  <input type="submit" value="Submit" method="post" formaction="/submit" />
</form>

TODO:

  • Add support for more field types
  • Move inputs inside labels for better clickability
  • More customization options for DaintyForm
  • More html boilerplate elements, such as div containers

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

dainty-0.3.0.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

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

dainty-0.3.0-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file dainty-0.3.0.tar.gz.

File metadata

  • Download URL: dainty-0.3.0.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.4.30

File hashes

Hashes for dainty-0.3.0.tar.gz
Algorithm Hash digest
SHA256 0906abddd2586823db50908f2abe397a5ed134352f344e75e69da7c3b27be5f9
MD5 f072296425b41ccc1180930d0602976d
BLAKE2b-256 a6d2881bfcedd986252e678a4cf498a1a4a75f9e82e6791f9410f1c1e5b5af14

See more details on using hashes here.

File details

Details for the file dainty-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: dainty-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.4.30

File hashes

Hashes for dainty-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 589ce3caa998a95fb5fc5e136fafb37105e26c0bee9dd4fc6ddd193d7c504874
MD5 b4e7d6a8ac11376660c0706d01ba9f92
BLAKE2b-256 39de66a61fefb9ca24b557d5741a26510ba4aa1a247e09b71c6ce42a17b9a3c4

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