Slim CI helps run only the parts of your data project that changed. It saves time and computing power by comparing the current state with the last run.
Slim CI with state comparison in dbt
dbt build --state path/to/previous/run --select state:modified
--state points to the folder with the previous run's manifest and run results.
--select state:modified runs only models that changed since the last run.
./target/previous_run.dbt build --state ./target/previous_run --select state:modified
dbt test --state ./target/previous_run --select state:modified
dbt run --state ./target/previous_run --select state:modified+
This Python script runs a dbt build command that uses slim CI with state comparison. It runs only the models that changed since the last run saved in ./target/previous_run. The output shows which models were run.
import os import subprocess # Assume previous run artifacts are saved in './target/previous_run' previous_state_path = './target/previous_run' # Command to run only modified models compared to previous run command = [ 'dbt', 'build', '--state', previous_state_path, '--select', 'state:modified' ] # Run the command and capture output result = subprocess.run(command, capture_output=True, text=True) print(result.stdout)
Make sure to save the previous run's artifacts (manifest.json, run_results.json) in the folder you point to with --state.
Slim CI only works if you have a previous run to compare with.
You can combine state:modified with other selectors like + to include dependencies.
Slim CI runs only changed models by comparing current and previous states.
Use --state to point to previous run artifacts and --select state:modified to select changed models.
This saves time and resources during development and testing.