mako(1)
Mako is a lightweight templating engine for Python that generates text output from templates with embedded Python logic.
Synopsis
mako [OPTION]... TEMPLATE [ARGUMENT=VALUE]...Description
Mako is a template library written in Python that compiles templates into Python modules for fast, flexible text generation. It supports embedded Python code, inheritance, includes, and filters, making it suitable for generating HTML, SQL, configuration files, and other text-based output.
The mako command-line tool allows you to render templates from the shell, passing arguments as key=value pairs. Templates use ${...} for variable substitution and can contain full Python code blocks for dynamic content generation.
Common options
| Flag | What it does |
|---|---|
-h, --help | show help message and exit |
-o, --output | output file path (default: stdout) |
-d, --data | variable definitions as JSON or key=value format |
-e, --encoding | template file encoding (default: utf-8) |
-M, --module-directory | directory for compiled template modules |
-D, --define | define a variable; repeatable for multiple definitions |
-l, --template-directory | directory to search for template imports |
Examples
render template.html with variables name and age, output to stdout
mako template.html name=John age=30render template with string literals and write to output.html
mako -o output.html template.html title='My Page' content='Hello World'pass variables as JSON data object to template
mako -d '{"user": "alice", "role": "admin"}' user_page.makostore compiled template modules in /tmp/mako_modules for performance
mako -M /tmp/mako_modules config.mako env=productionrender template with ISO-8859-1 encoding
mako -e iso-8859-1 template.txtrender template from stdin with piped input
echo '${greeting}, ${name}!' | mako /dev/stdin greeting=Hello name=Alice