htbuilder is a Python library for building HTML strings using a purely functional syntax, akin to JSX rather than traditional templating engines. It allows developers to construct HTML elements and attributes using Python functions, providing a clean and programmatic way to generate markup. The library is currently active, with its latest version being 0.9.0, released in September 2023.
pip install htbuilderVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create basic HTML elements, add text content, include attributes, and nest elements using `htbuilder`'s functional syntax. It shows both direct tag imports and the `H` factory for common tags.
Instead of `my-element(foo-bar='value')`, use `my_element(foo_bar='value')`.
Instead of `div(class='my-class')`, use `div(_class='my-class')`.
Embrace the functional Python syntax for defining elements, attributes, and children. Avoid trying to embed template-like logic.
Replace hyphens with underscores. E.g., `from htbuilder import my_component` instead of `my-component`, and `div(data_attribute='value')` instead of `div(data-attribute='value')`.
Prefix the reserved keyword with an underscore. For `class`, use `_class`. Example: `div(_class='my-css-class')`.
No dependency data recorded yet.