larztemplate
A tiny template engine — fill placeholders, loop and branch, render HTML.
Every real app builds strings from data: web pages, emails, config files. Rather
than messy string concatenation, you use a template. larztemplate is a small but
genuine template engine — {{ variables }}, {% for %} loops and {% if %}
branches — so you can generate HTML and text cleanly, and understand how
templating actually works. Zero dependencies.
Install
pip install larztemplate
Use
from larztemplate import render
render("Hello, {{ name }}!", {"name": "Ada"})
render("{% for x in items %}{{ x }} {% endfor %}", {"items": [1, 2, 3]})
render("{% if admin %}welcome boss{% else %}hi{% endif %}", {"admin": True})
render("<p>{{ msg }}</p>", {"msg": "<b>hi</b>"}, escape=True) # escapes the value
Learn to code with Larz
Part of the learn-to-code toolkit in the Larz stack — see the Learn to Code platform. A building block for real apps, and a readable example of parsing and rendering.
Tests
python -m unittest discover -s tests -v # 9 tests
License
MIT (c) larz-scripter
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file larztemplate-0.1.0.tar.gz.
File metadata
- Download URL: larztemplate-0.1.0.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f2445e1865a6659c8df3d981406fdb78091067f8e4d3e63591a5f7fcf49ad24
|
|
| MD5 |
af937412ce740050cd520c8fbbe97ba8
|
|
| BLAKE2b-256 |
92d8d18a183f84f71ea3c7f862307df3244c9b4dd30f423c082da827d801c783
|
File details
Details for the file larztemplate-0.1.0-py3-none-any.whl.
File metadata
- Download URL: larztemplate-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc1342540a452dc90eea2cf9bc346b49c792812406a43f1532dcc81d0fa0d841
|
|
| MD5 |
36cf43ed1172f1f69f44417a245f68cb
|
|
| BLAKE2b-256 |
cb7f58b91f1c6cf206b3bb1bd589546d280edef478e3f7137f5fc3528957bd2c
|