apache-airflow-providers-clickhousedb provider connects Airflow to ClickHouse, letting you run queries, create tables, and load data as part of a DAG. It connects over the HTTP interface using the clickhouse-connect client, and exposes ClickHouse through Airflow’s common SQL framework, so the standard SQLExecuteQueryOperator handles DDL, DML, and analytical queries with no ClickHouse-specific operator required.
Install the provider
Install the provider into the environment where your Airflow scheduler and workers run:apache-airflow-providers-common-sql and clickhouse-connect, which are installed alongside it. To pass query results to pandas or polars DataFrames, install the optional extras:
Create a ClickHouse connection
The provider registers a connection type ofclickhouse. Create a connection from the Airflow UI under Admin > Connections, or define one through the CLI or an environment variable.
In the UI, select ClickHouse as the connection type and fill in the fields:
For ClickHouse Cloud or any self-hosted cluster with TLS enabled, set
secure to true in the Extra field and use the TLS port (8443).
Extra connection options
The provider exposes additional options as dedicated fields in the connection form. When you define the connection by URI, JSON, or environment variable instead, supply them as keys in theextra JSON object. All are optional:
Define a connection without the UI
Set the connection through an environment variable. The URI form covers host, credentials, and database:clickhouse_default unless you specify another.
Run queries with SQLExecuteQueryOperator
Set the operator’sconn_id to your ClickHouse connection. The following DAG creates a table, inserts rows, reads them back, and drops the table:
handler (fetch_all_handler). To return something other than the full result set, pass a different handler, such as fetch_one_handler for the first row only.
Target a different database per task
When one connection points at a cluster and individual tasks query different databases, override the database throughhook_params instead of creating a separate connection:
Use the hook directly
For work that doesn’t fit a SQL operator — bulk inserts, streaming, or ClickHouse-specific client calls — useClickHouseHook inside a Python task.
The hook’s bulk_insert_rows method uses the native columnar insert path in clickhouse-connect, which is much faster than row-by-row inserts for large datasets. Set batch_size to bound peak memory on very large inputs:
get_client() to reach the underlying clickhouse-connect client for anything the hook doesn’t expose directly:
Apply session settings
Pass session settings when constructing the hook, either directly or through an operator’shook_params. Settings passed to the constructor are merged on top of any session_settings defined in the connection’s Extra field, and the constructor values win on conflicting keys: