Skip to main content
Help us improve PyPI by participating in user testing. All experience levels needed!

Library for generating HTML or XML in a pythonic way. Can fill HTML forms with default values and errors. Pure python alternative to html templating languages.

Project description

Some examples:

( full tutorial on yattag.org )

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!')

print(doc.getvalue())

Html form rendering example with default values

from yattag import Doc

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

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

print(doc.getvalue())

Full tutorial on yattag.org

Project details


Release history Release notifications

History Node

1.10.0

History Node

1.9.2

History Node

1.9.1

History Node

1.9.0

History Node

1.8.0

History Node

1.7.2

History Node

1.7.1

History Node

1.7.0

History Node

1.6.0

History Node

1.5.3

History Node

1.5.2

History Node

1.5.1

History Node

1.5.0

History Node

1.1.0

History Node

1.0.7

History Node

1.0.6

History Node

1.0.5

History Node

1.0.4

History Node

1.0.3

History Node

1.0.2

History Node

1.0.1

History Node

1.0.0

History Node

0.9.6

History Node

0.9.5

History Node

0.9.4

History Node

0.9.3

History Node

0.9.2

History Node

0.9.1

History Node

0.9.0

History Node

0.8.4

This version
History Node

0.8.3

History Node

0.8.2

History Node

0.8.1

History Node

0.8.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
yattag-0.8.3.tar.gz (5.9 kB) Copy SHA256 hash SHA256 Source None Apr 6, 2014
yattag-0.8.3.zip (8.1 kB) Copy SHA256 hash SHA256 Source None Apr 6, 2014

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page