Registry / serialization / tempita

tempita

JSON →
library0.6.0pypypi✓ verified 84d ago

Tempita is a very small, simple text templating language designed for text substitution, not as a full-fledged web templating engine. It's suitable for generating Python files, configuration files, or other text-based content when `string.Template` is insufficient, but a heavier solution like Jinja is overkill. The current version is 0.6.0, which is Python 3 only. The project is explicitly in maintenance mode, not actively developed for new features.

pip install tempita
INSTALL
IMPORT
SIG · TEMPITA
T
tempita
serializationpythonv0.6.0
Install
1.5s avg
Import
42ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.6.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.043s · 17.9MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.5s · import 0.042s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Template
from tempita import Template
import tempita; tempita.Template(...)
While 'import tempita' works, accessing 'Template' directly from the module without explicit import is less idiomatic and can lead to confusion if other module-level functions are expected.
sub
from tempita import sub
HTMLTemplate
from tempita import HTMLTemplate
Used for templates producing HTML, providing automatic HTML quoting.

This quickstart demonstrates both the `Template` class for creating reusable template objects and the `sub` function for immediate string substitution. It also includes an example using Tempita's control flow (`for`, `if`) and inline Python blocks (`py:`).

from tempita import Template, sub # Using the Template class tmpl = Template("Hello {{name}}! The answer is {{2 * 3}}.") output_class = tmpl.substitute(name='World') print(f"Class Output: {output_class}") # Using the sub shortcut for immediate substitution output_shortcut = sub("Welcome, {{user}}!", user='Alice') print(f"Shortcut Output: {output_shortcut}") # Example with control flow (if/for) and Python blocks complex_template = Template(""" <ul> {{for item in items}} <li>{{item.upper()}}{{if loop.last}} (last){{endif}}</li> {{endfor}} </ul> {{py: x = 10}} The value of x is {{x}}. """) output_complex = complex_template.substitute(items=['apple', 'banana', 'cherry']) print("\nComplex Output:") print(output_complex)
Debug
Known issues
breakingTempita version 0.6.0 and later removes Python 2 support. Projects upgrading to 0.6.0 must be running on Python 3, or they will encounter compatibility errors.
fix
Ensure your project is running on Python 3 before upgrading to tempita==0.6.0. If Python 2 compatibility is required, pin to an older version (e.g., `tempita<0.6.0`).
affects: 0.6.0+
gotchaTempita templates execute arbitrary Python code. This means templates should be treated as trusted code, as untrusted templates could pose a security risk by executing malicious operations.
fix
Only use templates from trusted sources. Do not render user-provided templates directly without sanitization or sandboxing, which Tempita does not provide inherently.
affects: All versions
gotchaTempita is not designed for complex web applications or extensive feature sets found in larger templating languages like Jinja. It's intended for simpler text substitution and code generation tasks.
fix
Evaluate if Tempita's minimalist feature set meets your project's needs. For complex web rendering or rich templating features, consider alternatives.
affects: All versions
Errors
Common errors & fixes
NameError: name 'Template' is not defined
The `Template` class was used without being explicitly imported from the `tempita` module.
fix
Add `from tempita import Template` at the top of your Python file.
tempita.TemplateError: Syntax error in template (template_name.html:X:Y)
There is a syntax error within the Tempita template string or file, such as a missing `{{endfor}}` or incorrect expression syntax.
fix
Review the template content around the reported line number (X) and column (Y) in the error message for syntax mistakes.
TypeError: 'str' does not support the buffer interface (or similar UnicodeDecodeError on Python 2)
Attempting to use Tempita 0.6.0+ on a Python 2 environment, or encountering unicode/bytes mixing issues in older versions.
fix
Ensure your environment is running Python 3 for Tempita 0.6.0+. For older Tempita versions, explicitly encode/decode strings to handle Unicode consistently, usually to UTF-8.
Upgrade
Version history
0.6.0latest on PyPI · released Nov 12, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
16 hits · last 30 days
node
12
OpenAI (training)
1
Resources
tempita — pip install tempita · libregistry