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)

Release files for yatl 20260805.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yatl 20260805.1
File Size Uploaded
yatl-20260805.1.tar.gz 22.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for yatl 20260805.1
File Interpreter ABI Platform
yatl-20260805.1-py3-none-any.whl Python 3 none any Details

Total release size: 42.2 kB

Release files / yatl-20260805.1.tar.gz

Download URL yatl-20260805.1.tar.gz
Size 22.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ca09b1a4be97dece288db44a98dbdd3070f889381e503bc5be7603829879e92e
BLAKE2b-256 checksum
How to use checksums
33bf5456f2fa12811b4ce4dd82741ad781d834ff4f4865b75f775e50c3e9ac3e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.12

Release files / yatl-20260805.1-py3-none-any.whl

Download URL yatl-20260805.1-py3-none-any.whl
Size 19.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
12222e2b0b9d38113ef9d61c230ca572a738727f8b91457cea703d0e99ae31b5
BLAKE2b-256 checksum
How to use checksums
29ed0176cb9cec10fbce6ef74a31150b5f6e5e125864efe472becf14d7ad1cff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.12
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page