Skip to main content

Yet Another Template Language

This is the web2py template language described here made available as stand alone package so it can be used anywhere.

Basically it is pure Python within "{{" ... "}}" delimiters and blocks are terminated with "pass" if termination is not obvious. There is no indentation constraints.

For example:

from yatl import render, SPAN

example = """
<div> 
{{ for k in range(num): }}
<span>{{=SPAN(k, _class='number')}} is {{if k % 2 == 0:}}even{{else:}}odd{{pass}}</span>
{{ pass }}
</div>
"""

print(render(example, context=dict(num=10, SPAN=SPAN), delimiters="{{ }}"))

In the example SPAN is an optional helper. Output is escaped by default unless marked up with the XML helper as in {{=XML('1 < 2')}}. Note that the helpers included here are similar but not identical to the web2py ones. They are 99% compatible but the implementation is different.

Any Python expressions is allowed in templates, including function and class defintions:

example = """
{{ def link(x): }}<a href="{{=x}}">{{=x}}</a>{{ pass }}
<ul>
  {{ for k in range(num): }}
  <li>
     {{= link('http://example.com/%s' % k) }}
  </li>
  {{ pass }}
</ul>
"""

print(render(example, context=dict(num=10), delimiters="{{ }}"))

Caching

If you implement a caching reader as the one below, you mak yatl even faster:

CACHE = {}
def reader(filename):
    if filename in CACHE:
        return CACHE[filename]
    with open(filename) as fp;
        CACHE[filename] = content = fp.read()
    return content
      
output = yatl.render(reader(filename), path=path, reader=reader)

Download files

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

Source Distribution

yatl-20260805.1.tar.gz (22.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yatl-20260805.1-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file yatl-20260805.1.tar.gz.

File metadata

  • Download URL: yatl-20260805.1.tar.gz
  • Upload date:
  • Size: 22.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.12

File hashes

Hashes for yatl-20260805.1.tar.gz
Algorithm Hash digest
SHA256 ca09b1a4be97dece288db44a98dbdd3070f889381e503bc5be7603829879e92e
MD5 520fff685092743ec36879f439cc8bc0
BLAKE2b-256 33bf5456f2fa12811b4ce4dd82741ad781d834ff4f4865b75f775e50c3e9ac3e

See more details on using hashes here.

File details

Details for the file yatl-20260805.1-py3-none-any.whl.

File metadata

  • Download URL: yatl-20260805.1-py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.12

File hashes

Hashes for yatl-20260805.1-py3-none-any.whl
Algorithm Hash digest
SHA256 12222e2b0b9d38113ef9d61c230ca572a738727f8b91457cea703d0e99ae31b5
MD5 6de5f4b0d488f066a342c3cc09924611
BLAKE2b-256 29ed0176cb9cec10fbce6ef74a31150b5f6e5e125864efe472becf14d7ad1cff

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page