Airium

raw JSON →
0.2.7 verified Fri May 01 auth: no python

Airium is a Python library for building HTML with natural syntax correspondence (python -> html). It requires no templates and has no dependencies. Current version is 0.2.7, with infrequent releases.

pip install airium
error ImportError: cannot import name 'airium' from 'airium'
cause Incorrect import: trying to import the module name instead of the class.
fix
Use 'from airium import Airium' instead of 'import airium' or 'from airium import airium'.
error AttributeError: 'Airium' object has no attribute 'html'
cause Using method calls without context manager; the html() method must be called with 'with' to generate the doctype and root element.
fix
Use 'with a.html():' to start the document, then nest other tags inside.
gotcha Airium uses context managers for nested HTML structure; forgetting to use 'with' for tags that contain children leads to incorrect HTML (tags will self-close or produce unexpected output).
fix Always use 'with' statements for tags that should enclose other elements (e.g., with a.div(): ...).
gotcha Airium does not validate attribute names; typos in attribute names are silently ignored and not rendered in output.
fix Double-check attribute names; refer to HTML spec for standard attributes.

Create an Airium instance, use context managers for tags, and convert to string.

from airium import Airium

a = Airium()
with a.html():
    with a.body():
        a.h1('Hello, World!')
result = str(a)
print(result)