Simple HTML Generation https://minihtml.trendels.name/
Python 95.5%
Just 1.7%
Batchfile 1.2%
Makefile 1.0%
HTML 0.6%
Other 0.1%
75 1 0

Clone this repository

https://tangled.org/trendels.name/minihtml https://tangled.org/did:plc:q2qfgufdtarvuca35hqm2jdq/minihtml
git@tangled.org:trendels.name/minihtml git@tangled.org:did:plc:q2qfgufdtarvuca35hqm2jdq/minihtml

For self-hosted knots, clone URLs may differ based on your setup.

Download tar.gz
README.md

minihtml - Simple HTML Generation#

PyPI - Version

minihtml is a library to generate HTML documents from Python. It aims to provide an API that allows you to define the structure of an HTML document in a succinct and natural way.

By building up nested HTML elements using context managers, you can combine HTML generation with control flow statements in a way that is easy to read and does not obscure the structure of the resulting HTML document.

Installation#

Install the minihtml package from PyPI:

pip install minihtml

or

uv add minihtml

Example#

A basic "hello, world" example:

>>> from minihtml.tags import html, head, title, body, div, p, a, img, ul, li
>>> links = [("Home", "/"), ("About Me", "/about"), ("Projects", "/projects")]
>>> with html(lang="en") as elem:
...     with head:
...         title("hello, world!")
...     with body, div["#content main"]:
...         p("Welcome to ", a(href="https://example.com/")("my website"))
...         img(src="hello.png", alt="hello")
...         with ul:
...             for title, url in links:
...                 li(a(href=url)(title))
...
<...>
>>> print(elem)
<html lang="en">
  <head>
    <title>hello, world!</title>
  </head>
  <body>
    <div id="content" class="main">
      <p>Welcome to <a href="https://example.com/">my website</a></p>
      <img src="hello.png" alt="hello">
      <ul>
        <li><a href="/">Home</a></li>
        <li><a href="/about">About Me</a></li>
        <li><a href="/projects">Projects</a></li>
      </ul>
    </div>
  </body>
</html>

License#

Minihtml is released under the MIT license. See LICENSE for more information.