hyperscript

0.3.0 · active · verified Thu Apr 16

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.

Common errors

Warnings

Install

Imports

Quickstart

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)

view raw JSON →