skip to navigation
skip to content

yattag 0.9.5

Generate HTML or XML in a pythonic way. Pure python alternative to web template engines.Can fill HTML forms with default values and error messages.

Latest Version: 1.5.2

Some examples:

( full tutorial on )

Basic example

Nested html tags, no need to close tags.

from yattag import Doc

doc, tag, text = Doc().tagtext()

with tag('html'):
    with tag('body', id = 'hello'):
        with tag('h1'):
            text('Hello world!')


Html form rendering example with default values

from yattag import Doc

doc, tag, text = Doc(
    defaults = {'ingredient': ['chocolate', 'coffee']}

with tag('form', action = ""):
    with tag('label'):
        text("Select one or more ingredients")
    with = 'ingredient', multiple = "multiple"):
        for value, description in (
            ("chocolate", "Dark chocolate"),
            ("almonds", "Roasted almonds"),
            ("honey", "Acacia honey"),
            ("coffee", "Ethiopian coffee")
            with doc.option(value = value):
    doc.stag('input', type = "submit", value = "Validate")


Full tutorial on

GitHub repo:

File Type Py Version Uploaded on Size
yattag-0.9.5.tar.gz (md5) Source 2014-05-01 8KB (md5) Source 2014-05-01 10KB
  • Downloads (All Versions):
  • 35 downloads in the last day
  • 877 downloads in the last week
  • 4078 downloads in the last month