$linuxjunkies
>

mako(1)

Mako is a lightweight templating engine for Python that generates text output from templates with embedded Python logic.

UbuntuDebianFedoraArch

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

FlagWhat it does
-h, --helpshow help message and exit
-o, --outputoutput file path (default: stdout)
-d, --datavariable definitions as JSON or key=value format
-e, --encodingtemplate file encoding (default: utf-8)
-M, --module-directorydirectory for compiled template modules
-D, --definedefine a variable; repeatable for multiple definitions
-l, --template-directorydirectory to search for template imports

Examples

render template.html with variables name and age, output to stdout

mako template.html name=John age=30

render 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.mako

store compiled template modules in /tmp/mako_modules for performance

mako -M /tmp/mako_modules config.mako env=production

render template with ISO-8859-1 encoding

mako -e iso-8859-1 template.txt

render template from stdin with piped input

echo '${greeting}, ${name}!' | mako /dev/stdin greeting=Hello name=Alice