Registry / web-framework / mako
library1.4.1pypypi✓ verified 25d ago

Mako is a hyperfast and lightweight templating language for Python, designed to be both powerful and easy to use. The current version is 1.3.10, released on March 28, 2026. Mako follows a regular release cadence, with updates addressing bugs and improvements.

pip install mako
INSTALL
IMPORT
SIG · MAKO
M
mako
web-frameworkpythonv1.4.1
Install
1.9s avg
Import
171ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.4.1 · 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.95 runs
installs and imports cleanly · install 0.0s · import 0.178s · 18.6MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.9s · import 0.164s · 19MB
17MB installed
● package 17MB
Code
Verified usage

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

Template
from mako.template import Template
Ensure correct import path to access the Template class.
TemplateLookup
from mako.lookup import TemplateLookup
Ensure correct import path to access the TemplateLookup class.

This example demonstrates how to set up a template lookup, load a template, and render it with variables using Mako.

from mako.template import Template from mako.lookup import TemplateLookup # Set up template lookup mylookup = TemplateLookup(directories=['/path/to/templates']) # Load a template mytemplate = mylookup.get_template('mytemplate.html') # Render the template with variables output = mytemplate.render(variable1='value1', variable2='value2') print(output)
Debug
Known issues
breakingMako now requires Python >= 3.7, removing support for Python 2 and Python 3.6.
fix
Upgrade your Python environment to version 3.7 or later.
affects: 1.3.10
deprecatedThe use of 'import="*"' in <%namespace> is known to decrease performance and will be fixed in a future release.
fix
Avoid using 'import="*"' in <%namespace> tags to maintain optimal performance.
affects: 1.3.10
breakingMako failed to locate a template file, resulting in a TopLevelLookupException. This typically occurs when the template file does not exist at the specified path or the template lookup directories are not configured correctly.
fix
Ensure the template file exists and that the mako.lookup.TemplateLookup object is initialized with the correct 'directories' parameter pointing to the template's location.
affects: 1.3.10
breakingMako raises `TopLevelLookupException` when a template file specified cannot be found in the configured lookup directories.
fix
Ensure the template file exists at the specified path and that Mako's `TemplateLookup` object is correctly initialized with the directory containing the template.
affects: 1.3.10
Errors
Common errors & fixes
NameError: name 'some_variable' is not defined
A variable is referenced in the Mako template that was not passed into the `render()` context, or `strict_undefined=True` is enabled and a variable is missing.
fix
Ensure all variables used in the template are passed in the dictionary to `template.render()`. For clearer debugging, initialize `Template` or `TemplateLookup` with `strict_undefined=True` to get specific `NameError` messages including the variable name.
ModuleNotFoundError: No module named 'mako'
The Mako library is not installed in the Python environment being used, or the Python interpreter cannot find it in its `sys.path`.
fix
Install Mako using pip: `pip install mako`. Verify that the correct Python environment's pip is used for installation.
SyntaxError: invalid syntax
There is a Python syntax error within a `<% ... %>` block in the Mako template, or Mako's special tags (`<%`, `%>`, `${}`) are used incorrectly or unescaped in content that Mako tries to parse as code.
fix
Carefully review the Python code within template blocks for syntax correctness (e.g., missing colons, incorrect indentation). If Mako tags are intended as literal text, escape them (e.g., write `<%%` for `<%`).
TypeError: 'Undefined' object is not callable
An undefined variable, represented by Mako's `UNDEFINED` object when `strict_undefined=False`, is treated as if it were a callable function or an object with attributes.
fix
Explicitly pass the expected variable to the template's rendering context or check for its existence (e.g., `if var is not UNDEFINED:`) before attempting to call methods or access attributes. Alternatively, initialize `Template` or `TemplateLookup` with `strict_undefined=True` to raise a `NameError` for missing variables sooner.
mako.exceptions.TopLevelLookupException: Cant locate template for uri %r
Mako's `TemplateLookup` cannot find an included (`<%include>`) or inherited (`<%inherit>`) template file at the specified URI within its configured `directories`.
fix
Verify that the `directories` argument passed to `TemplateLookup` correctly points to the location of your template files and that the URI used in `<%include>` or `<%inherit>` tags is correct and relative to those directories.
Upgrade
Version history
1.4.1latest on PyPI · released Aug 5, 2026
Audit
Dependencies
markupsaferequiredProvides escaping functions for HTML and XML
Agent activity
9 hits · last 30 days
node
8
Resources
mako — pip install mako · libregistry