Skip to main content

HyperText with Python

Project description

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>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hyperscript-0.3.0.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

hyperscript-0.3.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file hyperscript-0.3.0.tar.gz.

File metadata

  • Download URL: hyperscript-0.3.0.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for hyperscript-0.3.0.tar.gz
Algorithm Hash digest
SHA256 77e9372c09dbf0ec0e18515cd7e13a44cac7cbf800362a1eac26d9f8c4abe2a8
MD5 15d5ccc3097feebad37fa1298a011dbd
BLAKE2b-256 f1823494aa2c07252755d0e77068239712c35c897fca0830dfd8525369eae67d

See more details on using hashes here.

File details

Details for the file hyperscript-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: hyperscript-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for hyperscript-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5b1689c5cd4ab7c076a0bc61bff11200aa2e0e788bb50358be496e77924df4f0
MD5 a2e04ef6d95b5753f3b03036f38eeac0
BLAKE2b-256 d42d05a668e7dd7eaf0d7ee9bc162ebf358e9be9af43e4720cdecf622ccc6c9b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page