Yattag is a Python library for generating HTML or XML in a pythonic way. It offers a pure Python alternative to web template engines, allowing developers to create dynamic HTML documents programmatically. A notable feature is its ability to fill HTML forms with default values and error messages. The current stable version is 1.16.1, released on November 2, 2024, with an active but irregular release cadence.
pip install yattagVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to create a basic HTML document using Yattag's `Doc`, `tag`, and `text` methods. It also shows how to apply attributes, including the special `klass` for HTML `class`, and how to use the `indent` function for more readable output.
Instead of `with tag('div', class='my-class')`, use `with tag('div', klass='my-class')`.Instead of `with tag('div', data-id='123')`, use `with tag('div', ('data-id', '123'))`. For boolean attributes, you can use `with tag('html', 'ng-app')` or `with tag('script', defer='defer')`.For raw content, use `doc.asis('<script>alert("hello");</script>')` instead of `text('<script>alert("hello");</script>')`.After generating your document, pass the result to `indent()`: `print(indent(doc.getvalue()))`. You can also configure indentation options.
No dependency data recorded yet.