Skip to Content

Airflow

thunderduck-airflow is the Apache Airflow provider for Thunderduck, published on PyPI as thunderduck-airflow. It runs SQL through the same REST API as the other clients: submit, poll, cancel, and hand the execution id to the next task.

Source, issues and the license are in the thunderduck-airflow repository on GitHub .

pip install thunderduck-airflow

Requires Airflow 3.0+ and Python 3.11+. (Airflow 2 reached end of life on 2026-04-22 and is not supported.)

The connection

Create a connection of type Thunderduck in the UI, or:

airflow connections add thunderduck_default \ --conn-type thunderduck \ --conn-host api.thunderduck.ai \ --conn-password "$THUNDERDUCK_TOKEN"

The host is the API endpoint (https:// optional), the password is the API token, and the extras are optional:

{"endpoint": "https://api.thunderduck.ai", "timeout": 3600, "poll_interval": 2}

timeout is how long to wait for a run, poll_interval is the delay between status checks, and endpoint overrides host/port. Test connection does one authenticated GET /catalog/schema.

Running SQL

from thunderduck_airflow.operators.query import ThunderduckQueryOperator preview = ThunderduckQueryOperator( task_id="preview", sql=""" SELECT region, sum(total) AS revenue FROM sales_pg.public.orders GROUP BY region ORDER BY revenue DESC """, fetch_rows=50, )

The task pushes this to XCom:

{"execution_id": "…", "row_count": 12, "columns": ["region", "revenue"], "rows": [...]}

columns and rows appear only when fetch_rows is set. XCom is a metadata-database column: keep it small and pass the execution id for anything larger.

sql is templated, and a path ending in .sql is read from the DAG folder:

ThunderduckQueryOperator(task_id="daily", sql="sql/daily_revenue.sql")

A run that ends in error, is cancelled, or misses its deadline fails the task. The operator asks Thunderduck to cancel the run first, so a retry does not leave the previous execution running; on_kill does the same when the task is cleared or the worker is asked to stop.

Deferring the wait

from thunderduck_airflow.operators.query_async import ThunderduckQueryAsyncOperator rollup = ThunderduckQueryAsyncOperator( task_id="daily_rollup", sql="CREATE OR REPLACE TABLE lake.default.daily_revenue AS …", poll_interval=10, timeout=1800, )

The task submits and defers; the triggerer polls, so no worker slot is held. The trigger resolves the connection itself, so the token never travels through the metadata database. This needs a running triggerer component.

Waiting on an execution submitted elsewhere

from thunderduck_airflow.sensors.execution import ThunderduckExecutionSensor wait = ThunderduckExecutionSensor( task_id="wait_for_export", execution_id="{{ ti.xcom_pull(task_ids='submit_elsewhere')['execution_id'] }}", mode="reschedule", poke_interval=30, )

Useful when the submit happens in another DAG or outside Airflow. A failed or cancelled execution fails the sensor immediately rather than waiting out its timeout.

Errors

ExceptionMeaning
ThunderduckAuthErrorthe token was rejected (401/403)
ThunderduckQueryErrorthe run finished in the error state
ThunderduckTimeoutthe run was still going at the deadline
ThunderduckErroranything else: unreachable API, 4xx/5xx, cancelled run

All of them derive from AirflowException, and none of them includes the token in its message.