Powerful, composable, performant, convenient, Python-centric templating.

Looking for a more modern, Python-centric templating approach that resembles frontend solutions like JSX? is a Python implementation of htm. With you use an f-string-like value with native Python expressions to generate a virtual DOM (VDOM) data structure, then pass it to a compatible renderer for generating strings of markup. tracks the syntax and features of htm (JS), so if you like htm, you’ll like Since Python’s f-strings don’t match JavaScript’s tagged templates, uses the companion package tagged as a bridge.

Note is the first half of generating HTML. It generates a structural representation. To get from that, to an HTML string, you feed’s “VDOM” output into a renderer, such as hyperpython or a custom renderer. These docs give examples of both.


$ pip3 install htm


from htm import htm

def html(tag, props, children):
    return tag, props, children

a = 1
b = {"bar": 100}
c = "span"
d = "world"

  <div foo={a+2} ...{b}>
    <{c}>Hello, {d}!<//>
# ('div', {'foo': 3, 'bar': 100}, [('span', {}, ['Hello,', 'world', '!'])])


Running Tests

$ python3 -m unittest discover -s tests

Building Docs

Documentation is available in the docs directory. First install the dependencies then build the docs:

$ pip install -e .[docs]
$ cd docs
$ sphinx-build -b html . _build


This library is licensed under the MIT license. See [./LICENSE](./LICENSE).

Indices and tables