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
Metadata
Release files for dainty 0.6.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dainty-0.6.1.tar.gz | 35.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dainty-0.6.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 43.8 kB
Release files / dainty-0.6.1.tar.gz
| Download URL | dainty-0.6.1.tar.gz |
|---|---|
| Size | 35.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c65157c586c55520b8bef071d3a116aa66b5d22d4571d7f6e157fbb2634efcc4
|
|
BLAKE2b-256 checksum How to use checksums |
6a919a80d02b2931bec0747e80010dff881c192961b5aac4a633154c0325d9f4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.26
|
Release files / dainty-0.6.1-py3-none-any.whl
| Download URL | dainty-0.6.1-py3-none-any.whl |
|---|---|
| Size | 8.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ed172676747d61b255e39d195c801825efaf36e159de2e812e3e29865bdd81aa
|
|
BLAKE2b-256 checksum How to use checksums |
d6864f664c0170b81d6b6418228571ccbef4adcd2119cf0fc6e72baa582f4b44
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.26
|