Skip to main content

Hyperscript

Hyperscript is a lightweight library that allows you to write HTML with Python. It is heavily inspired by HyperScript.

Example usage

>>> print(h("p", "Hello world!"))
<p>Hello world!</p>

Class and id selectors

>>> print(h("p.class1#id", "Hello world!"))
<p class="class1" id="id">Hello world!</p>

Style

>>> print(h("p", "Hello world!", {"style": {"color": "red"}}))
<p style="color: red">Hello world!</p>

Nesting elements

>>> print(h("div", h("p", "Hello world!")))
<div><p>Hello world!</p></div>

Attributes

>>> print(h("a", {"href": "https://www.example.com"}, "link"))
<a href="https://www.example.com">link</a>

Boolean attributes

>>> print(h("input", {"type": "checkbox", "checked": True}))  # Behavior is the same if "checked" is None
<input type="checkbox" checked>
>>> print(h("input", {"type": "checkbox", "checked": ""}))
<input type="checkbox" checked="">
>>> print(h("input", {"type": "checkbox", "checked": False}))
<input type="checkbox">

Filtering out empty elements

>>> print(h("div", h("p", "Hello"), h("div", ""), h("p", "world!")))
<div><p>Hello</p><div></div><p>world!</p></div>
>>> print(h("div", h("p", "Hello"), h("div", ""), h("p", "world!"), remove_empty=True))
<div><p>Hello</p><p>world!</p></div>

Metadata

Release files for hyperscript 0.3.0

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

Source distribution (sdist)

Source distribution for hyperscript 0.3.0
File Size Uploaded
hyperscript-0.3.0.tar.gz 7.5 kB Details

Built distribution (wheel)

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

Total release size: 12.5 kB

Release files / hyperscript-0.3.0.tar.gz

Download URL hyperscript-0.3.0.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
77e9372c09dbf0ec0e18515cd7e13a44cac7cbf800362a1eac26d9f8c4abe2a8
BLAKE2b-256 checksum
How to use checksums
f1823494aa2c07252755d0e77068239712c35c897fca0830dfd8525369eae67d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.7

Release files / hyperscript-0.3.0-py3-none-any.whl

Download URL hyperscript-0.3.0-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5b1689c5cd4ab7c076a0bc61bff11200aa2e0e788bb50358be496e77924df4f0
BLAKE2b-256 checksum
How to use checksums
d42d05a668e7dd7eaf0d7ee9bc162ebf358e9be9af43e4720cdecf622ccc6c9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.7

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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