Skip to main content

Upload Python Package PyPI version Python Versions HTMLight

Abstract

Light html generator

Install

pip3 install htmlight

Disclaimer

Despite htmlight is able to generate full html page, it is designed to generate small fragments of code like:

from htmlight import h
from flask_babel import lazy_gettext
from flask_login import current_user


TEMPLATE = h.div(h.hr(), h.span("{hello} {username}"), h.hr())


def get_html():
    return TEMPLATE.format(hello=lazy_gettext("Hello"), username=current_user.name)

or

from htmlight import h
from flask_babel import lazy_gettext
from flask_login import current_user


def get_html():
    return h.div(h.hr(), h.span(lazy_gettext("Hello"), " ", current_user.name), h.hr()))

Usage

Code

from htmlight import h


landing_page = h.html(
    h.head(
        h.title("Welcome to Our Website"),
        h.link(rel="stylesheet", href="styles.css"),
    ),
    h.body(
        h.header(
            h.h1(
                "Welcome to Our Website",
                style=(
                    " color:"
                    " #333;"
                    " text-align:"
                    " center;"
                    " background-color:"
                    " #F0F0F0;"
                    " padding: 20px;"
                ),
            ),
            h.p(
                "Explore our amazing content",
                style="font-size: 20px; color: #555;",
            ),
        ),
        h.main(
            h.h2("Featured Articles", style="color: #444; text-align: center;"),
            h.article(
                h.h3("Article 1", style="color: #0072d6;"),
                h.p("This is the first article content", style="color: #666;"),
            ),
            h.article(
                h.h3("Article 2", style="color: #00a86b;"),
                h.p("This is the second article content", style="color: #666;"),
            ),
        ),
        h.footer(
            h.p(
                "© 2023 Our Website",
                style=(
                    "text-align: center;"
                    " background-color: #333;"
                    " color: #fff;"
                    " padding: 10px;"
                    " flex-shrink: 0;"
                    " background-color: #333;"
                    " position: absolute;"
                    " left: 0;"
                    " bottom: 0;"
                    " width: 100%;"
                    " overflow: hidden;"
                ),
            ),
        ),
    ),
    style="background-color: #f2f2f2; font-family: Arial, sans-serif;",
)

with open("landing_page.html", "w") as f:
    f.write(landing_page)

Result page

Result

Metadata

Release files for htmlight 0.2.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 htmlight 0.2.0
File Size Uploaded
htmlight-0.2.0.tar.gz 14.2 kB Details

Built distribution (wheel)

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

Total release size: 29.0 kB

Release files / htmlight-0.2.0.tar.gz

Download URL htmlight-0.2.0.tar.gz
Size 14.2 kB
Tags Source
SHA-256 checksum
How to use checksums
51e1c5f862c4ecb3a57247ad2df2d6015be652f2c2ec612821c5afa385aa6a6b
BLAKE2b-256 checksum
How to use checksums
1afa200198be8445fbe54c5687fa8815252366b905d8a97e55b454067dbfbfc7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / htmlight-0.2.0-py3-none-any.whl

Download URL htmlight-0.2.0-py3-none-any.whl
Size 14.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5f6b32c277beda0a39104533a1ff3c78800fae5f9b11a3ad2563dc88905e528a
BLAKE2b-256 checksum
How to use checksums
9e7eab92f39eda84fb3357278e14cb72c1f4f5fbb50f6a09fa9cf1cb30cfa16f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.2

2 release files

0.1.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