The "namespaces" doc seem to describe what you are after, specifically:
Namespaces can also import regular Python functions from modules. These callables need to take at least one argument,
context
, an instance ofContext
. A module file some/module.py might contain the callable:def my_tag(context): context.write("hello world") return ''
A template can use this module via:
<%namespace name="hw" module="some.module"/> ${hw.my_tag()}
..and:
The "custom tag" format is intended mainly for namespace functions which recognize body content, which in Mako is known as a “def with embedded content”:
<%mynamespace:somefunction arg1="some argument" args="x, y"> Some record: ${x}, ${y} </%mynamespace:somefunction>