Apache Airflow integration for dbt
Archived. The repository is read-only: no more fixes or releases will come.
Consider insteadairflow-dbt-pythonPythie’s Index: 6366.6K downloads/moCompare →
pip install airflow-dbtairflow-dbt
This is a collection of Airflow operators to provide easy integration with dbt.
from airflow import DAG
from airflow_dbt.operators.dbt_operator import (
DbtSeedOperator,
DbtSnapshotOperator,
DbtRunOperator,
DbtTestOperator
)
from airflow.utils.dates import days_ago
default_args = {
'dir': '/srv/app/dbt',
'start_date': days_ago(0)
}
with DAG(dag_id='dbt', default_args=default_args, schedule_interval='@daily') as dag:
dbt_seed = DbtSeedOperator(
task_id='dbt_seed',
)
dbt_snapshot = DbtSnapshotOperator(
task_id='dbt_snapshot',
)
dbt_run = DbtRunOperator(
task_id='dbt_run',
)
dbt_test = DbtTestOperator(
task_id='dbt_test',
retries=0, # Failing tests would fail the task, and we don't want Airflow to try again
)
dbt_seed >> dbt_snapshot >> dbt_run >> dbt_test
Installation
Install from PyPI:
pip install airflow-dbt
It will also need access to the dbt CLI, which should either be on your PATH or can be set with the dbt_bin argument in each operator.
Usage
There are five operators currently implemented:
DbtDocsGenerateOperator- Calls
dbt docs generate
- Calls
DbtDepsOperator- Calls
dbt deps
- Calls
DbtSeedOperator- Calls
dbt seed
- Calls
DbtSnapshotOperator- Calls
dbt snapshot
- Calls
DbtRunOperator- Calls
dbt run
- Calls
DbtTestOperator- Calls
dbt test
- Calls
Each of the above operators accept the following arguments: