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.2.1.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for hyperscript-0.2.1.tar.gz
Algorithm Hash digest
SHA256 05fdd6b9490454ec882f44279a2b007c9eedcba35d899fee8092ce373d1588bf
MD5 4e8728ef341daf44ea217052a18baf0d
BLAKE2b-256 04a015b9285a17e8d2bc319cc8f152d5bc768f880eda40424be6784871d91330

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hyperscript-0.2.1-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.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d27864bccf0403c7eaa0a6c91f4f4ec4f0cec6f6ea06afe8ae658df9af72228d
MD5 67263032f99881207ecfe16c6f0367a2
BLAKE2b-256 0bb6cd3b1241bf8dbfe64c55d498b09a4eeead94b2c3d6d7921f2e374a87bb96

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