Create a macro
Put project-wide macros in Python files under the top-levelmacros/ directory:
Call a macro from SQL
Use@macro_name(...) in a model query:
Arguments
Macro calls accept Python literal values:- Strings:
"value"or'value' - Numbers:
42,3.14,-1 - Booleans:
True,False - Lists:
[1, 2, 3] - Dictionaries:
{"key": "value"} None- The result of another macro call
Keep implementation details private
Only public functions owned by the file are exported as macros. Prefix helpers, constants, classes, and type aliases with_:
@completed_orders(). _status_filter and _DEFAULT_STATUS remain ordinary
Python implementation details.
Imported functions are not re-exported as new macros from the importing file.
Use macros in tests
Tests are SQL, so they can use macros as reusable fixture generators:Use macros in hooks
Macros work inside inline and named SQL hooks:Where macros work
Macros are supported in:- Model query SQL
- Inline and named SQL hooks
- Unit tests and scenarios
- Standalone audit SQL
- SQL functions and supported inline source expressions
MODEL() configuration fields. SQL hook entries are the
exception because their contents are SQL.
Next steps
Composition and Context
Compose macros through Python imports and use adapter or target context.
Declarations and Scopes
Limit a macro to one folder, or to that folder and its child folders.

