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
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.036s · 17.8MB
glibcpy 3.10–3.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)
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.
fixThe `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.
fixHTML 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.
Resources
No resource links recorded.