Skip to main content

A small library for generating HTML & CSS using Python syntax.

Project description

pyhtml5

A tiny Python library for writing HTML and CSS in code — with clear, full element names like Division, Paragraph, and Button. Render to a string in regular Python, or mount directly into the browser DOM when running under PyScript.


Why use it?

  • Readable structure: with Division(): Paragraph("Hello")
  • Works anywhere: strings in CPython, live DOM in PyScript
  • Built-in CSS: Stylesheet().rule(".card", padding="16px")

Install

pip install pyhtml5

Quick start

Build HTML (string)

from pyhtml5 import Division, Paragraph, Anchor, html_string

with Division(class_="card") as root:
    Paragraph("Hello from pyhtml5! ")
    Anchor("Read more", href="https://example.com", target="_blank")

print(html_string(root))

Use in PyScript (mount to the DOM)

from pyhtml5 import Division, Paragraph

with Division(class_="notice") as box:
    Paragraph("Running inside PyScript!")

box.mount("#app")   # or just box.mount() to append to <body>

CSS in code

from pyhtml5 import Stylesheet, css_string

with Stylesheet() as css:
    css.rule(":root", color_scheme="light dark")
    css.rule(".card", padding="16px", border="1px solid #ddd", border_radius="12px")

print(css_string(css))  # in PyScript, use css.mount() to inject a <style>

License

MIT License

See LICENSE for details.

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

pyhtml5-0.0.2.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyhtml5-0.0.2-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file pyhtml5-0.0.2.tar.gz.

File metadata

  • Download URL: pyhtml5-0.0.2.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pyhtml5-0.0.2.tar.gz
Algorithm Hash digest
SHA256 dc3717b341fcf3608a37d2821a284ffa5f0739e6e9609e4691e481eb1c076327
MD5 d5712a04df569c09cb426d7971b8d9b8
BLAKE2b-256 15669e694cc3a745b1cf1abf6c50f99b763e55b24b531c4486b992c5e1809a22

See more details on using hashes here.

File details

Details for the file pyhtml5-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: pyhtml5-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pyhtml5-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 068efd356ed2cb6da10dbe90630a67242e638a8bc82f9a9d48bd068b5e66367e
MD5 b37d64643ec6cba9db3e2cfc4b94d693
BLAKE2b-256 744a6fac26299050c6d2e0ce339a96b2f3988e77b1c6a3c3893b7fde61617290

See more details on using hashes here.

Supported by

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