{"id":406,"library":"mako","title":"Mako Templating Library","description":"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.","status":"active","version":"1.3.10","language":"python","source_language":"en","source_url":"https://github.com/makotemplates/mako","tags":["templating","Python","Mako","web development"],"install":[{"cmd":"pip install mako","lang":"bash","label":"Install Mako"}],"dependencies":[{"reason":"Provides escaping functions for HTML and XML","package":"markupsafe","optional":false}],"imports":[{"note":"Ensure correct import path to access the Template class.","symbol":"Template","correct":"from mako.template import Template"},{"note":"Ensure correct import path to access the TemplateLookup class.","symbol":"TemplateLookup","correct":"from mako.lookup import TemplateLookup"}],"quickstart":{"code":"from mako.template import Template\nfrom mako.lookup import TemplateLookup\n\n# Set up template lookup\nmylookup = TemplateLookup(directories=['/path/to/templates'])\n\n# Load a template\nmytemplate = mylookup.get_template('mytemplate.html')\n\n# Render the template with variables\noutput = mytemplate.render(variable1='value1', variable2='value2')\n\nprint(output)","lang":"python","description":"This example demonstrates how to set up a template lookup, load a template, and render it with variables using Mako."},"warnings":[{"fix":"Upgrade your Python environment to version 3.7 or later.","message":"Mako now requires Python >= 3.7, removing support for Python 2 and Python 3.6.","severity":"breaking","affected_versions":"1.3.10"},{"fix":"Avoid using 'import=\"*\"' in <%namespace> tags to maintain optimal performance.","message":"The use of 'import=\"*\"' in <%namespace> is known to decrease performance and will be fixed in a future release.","severity":"deprecated","affected_versions":"1.3.10"},{"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.","message":"Mako 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.","severity":"breaking","affected_versions":"1.3.10"},{"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.","message":"Mako raises `TopLevelLookupException` when a template file specified cannot be found in the configured lookup directories.","severity":"breaking","affected_versions":"1.3.10"}],"env_vars":null,"last_verified":"2026-05-12T13:37:01.074Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"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.","cause":"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.","error":"NameError: name 'some_variable' is not defined"},{"fix":"Install Mako using pip: `pip install mako`. Verify that the correct Python environment's pip is used for installation.","cause":"The Mako library is not installed in the Python environment being used, or the Python interpreter cannot find it in its `sys.path`.","error":"ModuleNotFoundError: No module named 'mako'"},{"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 `<%`).","cause":"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.","error":"SyntaxError: invalid syntax"},{"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.","cause":"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.","error":"TypeError: 'Undefined' object is not callable"},{"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.","cause":"Mako's `TemplateLookup` cannot find an included (`<%include>`) or inherited (`<%inherit>`) template file at the specified URI within its configured `directories`.","error":"mako.exceptions.TopLevelLookupException: Cant locate template for uri %r"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":0,"quickstart_tag":"stale","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.18,"mem_mb":5.8,"disk_size":"18.5M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.17,"mem_mb":5.6,"disk_size":"19M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.23,"mem_mb":6.4,"disk_size":"20.5M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.19,"mem_mb":6.4,"disk_size":"21M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.2,"mem_mb":6,"disk_size":"12.4M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.2,"mem_mb":6,"disk_size":"13M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.15,"mem_mb":5.4,"disk_size":"12.0M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.16,"mem_mb":5.4,"disk_size":"13M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.1,"mem_mb":4.2,"disk_size":"18.0M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.09,"mem_mb":4.2,"disk_size":"19M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}}