Registry / web-framework / hyperscript

hyperscript

JSON →
library0.3.0pypiunverified

hyperscript is a lightweight Python library for generating HTML, heavily inspired by the JavaScript HyperScript. It is currently at version 0.3.0 and sees releases periodically for fixes and minor enhancements.

pip install hyperscript
INSTALL
IMPORT
SIG · HYPERSCRIPT
H
hyperscript
web-frameworkenv0.3.0
Install
1.5s avg
Import
36ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.036s · 17.8MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.5s · import 0.036s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

h
from hyperscript import h
from hyperscript import div, p
Unlike some other 'hyperscript' inspired libraries, this Python 'hyperscript' only exposes a generic 'h' function for creating elements, not individual functions for each HTML tag.

This quickstart demonstrates how to create basic HTML elements, apply CSS classes and IDs directly in the tag name, add attributes and inline styles, and manage boolean attributes.

from hyperscript import h # Basic element print(h("p", "Hello world!")) # Element with class and ID print(h("div.container#main", h("h1", "Welcome"), h("p", "This is a paragraph."))) # Element with attributes and style print(h("a", {"href": "https://www.example.com", "style": {"color": "blue"}}, "Visit Example")) # Boolean attribute handling print(h("input", {"type": "checkbox", "checked": True})) # renders checked print(h("input", {"type": "checkbox", "checked": False})) # omits checked attribute print(h("input", {"type": "checkbox", "checked": None})) # renders checked (same as True)
Debug
Known issues
breakingVersion 0.3.0 introduced a breaking change by replacing 'pipe annotations'. Code relying on a previous, likely internal or specific, syntax using 'pipe annotations' for HTML generation will no longer work.
fix
Review your HTML generation logic, especially how complex attributes or nested structures were previously defined. Consult the GitHub repository for any updated patterns if your code was affected.
affects: >=0.3.0
gotchaBoolean HTML attributes (e.g., `checked`, `selected`) are handled specifically: `True` renders the attribute, `False` omits it entirely, and `None` also renders the attribute (without a value). This can be a source of confusion if `None` is expected to omit the attribute.
fix
Always use `False` explicitly if you want to ensure a boolean attribute is *not* present in the rendered HTML. Use `True` or `None` if you intend for the attribute to be present.
affects: All
Errors
Common errors & fixes
AttributeError: module 'hyperscript' has no attribute 'div'
Attempting to import or use specific HTML tag functions (e.g., `div()`, `p()`) directly from the `hyperscript` module.
fix
The `hyperscript` library by `vchan` only provides a single factory function, `h`. You must use `h("div", ...)` or `h("p", ...)` instead. Example: `from hyperscript import h; h("div", "Content")`.
SyntaxError: invalid syntax (for `class` attribute in keyword arguments) or `TypeError: h() got multiple values for argument 'class'`
Attempting to pass HTML attributes like `class` as a direct keyword argument named `class` (which is a reserved Python keyword) or providing attributes both via a dictionary and keyword arguments.
fix
HTML attributes should be passed either in the second argument as a dictionary (e.g., `h("p", {"class": "my-class"})`) or by including class/id selectors directly in the tag string (e.g., `h("p.my-class#my-id", "Text")`).
Upgrade
Version history
0.3.0latest on PyPI · released Oct 22, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources

No resource links recorded.

hyperscript — pip install hyperscript · libregistry