Skip to main content

Run Python before and after dbt models

Python scripts can be attached as either to run before or after a model. You have to add them in the meta section of the dbt model config to use:

- name: modela

after and before scripts vs post-hooks and pre-hooks

Starting with 0.4.0, we are deprecating after (and before) scripts in favor of the newly introduced post-hooks (and pre-hooks) for fal flow run. The table below is a general overview between these two features:

after scriptspost-hooks
Runs after the bound model
Run before dependant models (Runs as part of the bound model)✅ (after 0.4.0)
Parallelization (thread-level) is enabled
Runs even if the underlying model's dbt run fails
Can be parameterized
Can be individually selected / executed
Can use write_to_source/write_to_model❌ (use Python models instead)

If you have an existing project and want to move away from after scripts, please see the related section in the "Compatibility" page.