answerui
answerui styles semantic HTML for FastHTML apps. A component is an HTML tag, a variant or a state is an attribute, and classes do only utility jobs, so page markup stays small and readable. Every component’s CSS and behavior lives in one registry, and a page carries the whole registry as one stylesheet and one script. An app changes the look by registering ordinary CSS in the same registry, scoped to a token, a component, or a region.
answerui is built for a human working with an LLM in a persistent Python kernel. Its pyskill, answerui.skill, teaches the model the library: how a page is built, how to read what is registered, how to change it, and how to check the result.
Install
pip install -e .
Use
reg.hdrs() gives the stylesheet and the behavior script, and reg.ftrs() gives the sprite sheet for icons. Both render per response, so a rule registered later is in the next page:
from fasthtml.common import *
from answerui.all import *
app = FastHTML(hdrs=reg.hdrs(), ftrs=reg.ftrs())
rt = app.route
reg.serve(app) serves the same assets from URLs named by a hash of their content, which the browser caches. They are rebuilt when a rule changes, and the next page links the new build as a new URL.
A page is native HTML inside layout containers, with a component wherever the platform has no element for the job. Variants and severities are attributes:
page = Card(H2('Profile'), Field('Name', Input(name='name')), Cluster(Button('Save'), Button('Cancel', secondary=True)))
print(to_xml(page, Alert('Saved.', success=True, dismissible=True)))
<div stack card>
<h2>Profile</h2>
<div field>
<label>Name <input name="name">
</label> </div>
<div cluster>
<button>Save</button><button secondary>Cancel</button> </div>
</div>
<div card alert success>
<div stack style="--gap: var(--space-2);">Saved.</div>
<button type="button" secondary dismiss>Dismiss</button></div>
Rendered with the registry’s stylesheet. In a notebook, demo(page) shows the same thing live:
Customise
A change is ordinary CSS registered at the smallest scope that covers it: a token on the root for the whole app, a rule on a component, or a selector for a region. App rules sit in a cascade layer above the framework’s, so nothing in the framework needs editing:
reg.rule('theme', ':root { --hue: 150; --radius: 0; }')
Button.rule('caps', 'text-transform: uppercase;')
Button.caps [app] button, a[button]
A variant is a new treatment declared on the component. It becomes an attribute the constructor accepts and appears in the component’s documentation:
Button.variant('cta', '--pad-block: var(--space); --pad-inline: var(--space2); font-size: var(--text1);', doc='The landing page call to action.')
Button.cta [app] :is(button, a[button])[cta]: The landing page call to action.
Button
Button(*children, **attrs)
Raised at rest, down while active, busy, or expanded, latched by aria-pressed; secondary for the lesser action; a link carrying button is styled the same way.
Root selector: button, a[button].
Declared variants:
secondary: The lesser action: the neutral surface with a hairline border, and the accent wash when latched.quiet: No face, border, or shadow at rest, for an action that should not compete: dismiss, close, and toolbar buttons.editable: A value drawn as the dashed ghost of the well it becomes; click to edit, and the app swaps the form in.cta: The landing page call to action.
Rules:
base(components)icon-only(components): A button whose only child is an svg is square; give it an aria-label.caps(app)
Previews in notebooks
demo(page) renders markup in an iframe with the current stylesheet and behaviors. It returns a preview with two representations: the frame as HTML, and the markup as Markdown. The frame holds the whole stylesheet. Stored in a notebook, it would make a file with many previews large and rewrite every preview on each style change. The preview therefore marks its HTML with nbdev’s strip flag. nbdev-clean drops the frame and keeps the Markdown, so the committed notebook records what each preview showed. A fresh clone shows the frames again after the cells run.
For the docs, set exec_all in pyproject.toml:
[tool.nbdev]
exec_all = true
nbdev-docs then runs every notebook and renders each preview from the current code.
With an LLM
answerui.skill is a pyskill: a module whose docstring teaches a model the library. list_pyskills() finds it, doc(answerui.skill) is the guide, and doc(Button) describes a component, its variants, and its rules.
Metadata
Release files for answerui-py 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| answerui_py-0.0.2.tar.gz | 165.3 kB | Without provenance | Details for answerui_py-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| answerui_py-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for answerui_py-0.0.2-py3-none-any.whl |
Total release size: 334.4 kB
Release files / answerui_py-0.0.2.tar.gz
| Download URL | answerui_py-0.0.2.tar.gz |
|---|---|
| Size | 165.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b2d70b2ff88de244cb762958973c741b2badfd7944a1a1a225f6f072d2d73099
|
|
BLAKE2b-256 checksum How to use checksums |
2c05a41362ce45885f677f8155abf894c93a389986d586fd8fcf1ff2e68482af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Release files / answerui_py-0.0.2-py3-none-any.whl
| Download URL | answerui_py-0.0.2-py3-none-any.whl |
|---|---|
| Size | 169.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f03fba7c392ebdd1b6a649d505591b225a67584ea6fe5957bc1248678c178919
|
|
BLAKE2b-256 checksum How to use checksums |
1226c8b750cbcbcaa4f4b02ed29caf4b78438282427da0d1a357209886a4e51a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Security for answerui-py 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.