{"id":8705,"library":"tempita","title":"Tempita","description":"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.","status":"maintenance","version":"0.6.0","language":"en","source_language":"en","source_url":"https://github.com/TurboGears/tempita","tags":["templating","text-processing","code-generation","mini-language","python3-only"],"install":[{"cmd":"pip install tempita","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"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.","wrong":"import tempita; tempita.Template(...)","symbol":"Template","correct":"from tempita import Template"},{"symbol":"sub","correct":"from tempita import sub"},{"note":"Used for templates producing HTML, providing automatic HTML quoting.","symbol":"HTMLTemplate","correct":"from tempita import HTMLTemplate"}],"quickstart":{"code":"from tempita import Template, sub\n\n# Using the Template class\ntmpl = Template(\"Hello {{name}}! The answer is {{2 * 3}}.\")\noutput_class = tmpl.substitute(name='World')\nprint(f\"Class Output: {output_class}\")\n\n# Using the sub shortcut for immediate substitution\noutput_shortcut = sub(\"Welcome, {{user}}!\", user='Alice')\nprint(f\"Shortcut Output: {output_shortcut}\")\n\n# Example with control flow (if/for) and Python blocks\ncomplex_template = Template(\"\"\"\n<ul>\n{{for item in items}}\n  <li>{{item.upper()}}{{if loop.last}} (last){{endif}}</li>\n{{endfor}}\n</ul>\n{{py: x = 10}}\nThe value of x is {{x}}.\n\"\"\")\noutput_complex = complex_template.substitute(items=['apple', 'banana', 'cherry'])\nprint(\"\\nComplex Output:\")\nprint(output_complex)","lang":"python","description":"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:`)."},"warnings":[{"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`).","message":"Tempita 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.","severity":"breaking","affected_versions":"0.6.0+"},{"fix":"Only use templates from trusted sources. Do not render user-provided templates directly without sanitization or sandboxing, which Tempita does not provide inherently.","message":"Tempita 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Evaluate if Tempita's minimalist feature set meets your project's needs. For complex web rendering or rich templating features, consider alternatives.","message":"Tempita 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Add `from tempita import Template` at the top of your Python file.","cause":"The `Template` class was used without being explicitly imported from the `tempita` module.","error":"NameError: name 'Template' is not defined"},{"fix":"Review the template content around the reported line number (X) and column (Y) in the error message for syntax mistakes.","cause":"There is a syntax error within the Tempita template string or file, such as a missing `{{endfor}}` or incorrect expression syntax.","error":"tempita.TemplateError: Syntax error in template (template_name.html:X:Y)"},{"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.","cause":"Attempting to use Tempita 0.6.0+ on a Python 2 environment, or encountering unicode/bytes mixing issues in older versions.","error":"TypeError: 'str' does not support the buffer interface (or similar UnicodeDecodeError on Python 2)"}]}