Compose helpers in one file
Use underscore-prefixed helpers for implementation details that should not be callable from SQL:cents_to_dollars is exported as a SQLBuild macro.
Public macros in the same file are also ordinary Python functions and may call one another:
Compose macros from different files
Import another project macro when it is visible from the importing macro file:add_tax and round_money retain their original identities; only formatted_order_total is newly
exported by orders.py.
The same visibility direction applies to scoped macros:
- A scoped macro may import a project-wide macro.
- A scoped macro may import a macro available from its own or an ancestor directory.
- A project-wide macro cannot import a narrower macro.
- A macro cannot import from a sibling or unrelated scope.
_macros/
or _local_macros/.
Macro output is final SQL
Do not return SQL containing another@macro() call:
Nested calls written in SQL
The SQL author may explicitly pass one macro’s result to another:add_tax first and passes its returned string to round_money. This is not a
second expansion of generated output: both calls are visible in the SQL source.
Inner macros may return any Python value accepted by the outer macro. A macro used directly in SQL
must return a string.
Macro context
When the first parameter is namedctx, SQLBuild passes a MacroContext with adapter, target, and
project-variable information:

