Skip to main content

answerui

answerui styles semantic HTML for FastHTML apps. Page markup stays small and readable because each component is an HTML tag, each variant or state is an attribute, and classes are used only for utilities. One registry holds every component’s CSS and behavior. Each page includes 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 how to build a page, read and change what is registered, and 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. A rule registered after the app is created still appears on the next page, because both are rendered again for each response:

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 at URLs named by a hash of their content. The browser fetches each URL once and caches it. When a rule changes, the assets are rebuilt and the next page links to them at new URLs.

A page is native HTML inside layout containers, with a component wherever HTML 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>

The image below is that markup rendered with the registry’s stylesheet. In a notebook, demo(page) shows the same thing live:

Customise

Register ordinary CSS at the smallest scope that covers the change: a token on the root for the whole app, a rule on a component, or a selector for a region. Because the app cascade layer comes after every framework layer except utilities, app rules override the framework’s styles with no edit to the framework:

reg.rule(':root { --hue: 150; --radius: 0; }')
Button.rule('caps', 'text-transform: uppercase;')
Button.caps [app] button, a[button]

A variant is a new style declared on a component. The component’s constructor accepts it as an attribute, and the component’s documentation lists it:

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 with an aria-label whose only child element is an svg is square; a button with an icon and a text label keeps the usual padding.
  • 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. Storing frames would make a notebook with many previews large, and each style change would alter every stored preview. 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. In a fresh clone, run the cells to show the frames again.

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.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for answerui-py 0.0.3
File Size Uploaded Provenance Actions
answerui_py-0.0.3.tar.gz 165.9 kB Without provenance Details for answerui_py-0.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for answerui-py 0.0.3
File Interpreter ABI Platform Actions
answerui_py-0.0.3-py3-none-any.whl Python 3 none any Details for answerui_py-0.0.3-py3-none-any.whl

Total release size: 335.5 kB

Release files / answerui_py-0.0.3.tar.gz

Download URL answerui_py-0.0.3.tar.gz
Size 165.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ffe4817b57b0b19fa290fb85b0bf16e98343483e93a20223636d0629279cb25c
BLAKE2b-256 checksum
How to use checksums
22462d1dbb8e1df7e4b740c4fcc5d195525c2d0e047d3ab5a0364fc0fee59d52
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.3-py3-none-any.whl

Download URL answerui_py-0.0.3-py3-none-any.whl
Size 169.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a19e7573cf7d07554db7f2924418c605a20400138fced7f576c2745501698752
BLAKE2b-256 checksum
How to use checksums
204f1bdd039efc559846689511bc28d79a314d2ab6903dd1ce250c5ce192b24e
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.3

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page