Skip to main content

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 0.0.1

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 0.0.1
File Size Uploaded Provenance Actions
answerui-0.0.1.tar.gz 166.7 kB Without provenance Details for answerui-0.0.1.tar.gz

Built distribution (wheel)

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

Total release size: 337.4 kB

Release files / answerui-0.0.1.tar.gz

Download URL answerui-0.0.1.tar.gz
Size 166.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a5e41aff026843eaa6863d0967fa869340b6ac1b90637029145ac83f27b87393
BLAKE2b-256 checksum
How to use checksums
df8726a17cd27f1b0eb9dc6f8f5add30ffcc9402fc382022e15ce03ac07fa763
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.11

Release files / answerui-0.0.1-py3-none-any.whl

Download URL answerui-0.0.1-py3-none-any.whl
Size 170.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ddebe0f6b5f03ce308559b8c2218f69a8dec9785e5a8d67c2b49cb53f7793ed4
BLAKE2b-256 checksum
How to use checksums
7eaf62178331f6d072f76abd98c5eaad92864b7877ac1f01a90b2bb1e7eda5af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.11

Security for answerui 0.0.1

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.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

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