Define a Python hook
SQLBuild discovers decorated functions recursively from.py files under hooks/python/:
hooks/python/notifications.py
name and description arguments. A Python file may define multiple decorated hooks.
Files named __init__.py or beginning with _ are skipped. Imported decorated functions are not registered again from the importing module.
Invoke a Python hook
Reference the hook by name and optionally pass keyword arguments:@@CTX:... or @macro() reaches the function unchanged.
Signature validation
Unknown hooks, unknown keyword arguments, missing required arguments, required positional-only arguments, and arguments that conflict with context or provider injection fail compilation. A function with**kwargs can accept additional configured arguments.
Python hooks must return None or ctx.skip(...). Any other return value fails execution.
Hook context
Python hooks declare aHookContext parameter named ctx, context, _ctx, or hook_context. It need not be the first parameter when providers or configured arguments are also present:
Providers
Providers may be injected into Python hook parameters by name or accessed throughctx.providers. They are resolved lazily using the same lifecycle as loaders, tasks, assets, and checks. SQL hooks cannot use providers because they are compiled SQL statements rather than Python callables.
Skips and failures
Returningctx.skip(...) stops the remaining hooks in the current phase. Runtime exceptions fail that lifecycle phase. See Lifecycle and failure timing for the effects of pre-hook and post-hook skips, soft and hard modes, and failures after warehouse mutation.
Identity and diagnostics
Python hook invocations and version hashes participate in model identity as described in Names and identity. Executed hooks also record their own fingerprints after successful completion or an explicit skip. Compilation reports unknown hooks and invalid signatures with the model name and indexed invocation label, such aspost_hooks[1] python("notify_complete"). Runtime output preserves the authored index and hook name. Exceptions and unsupported return values fail with the Python hook identity attached.
