> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# dltHub and ClickHouse Cloud

> Load data into ClickHouse with dltHub: create a workspace, deploy, schedule and run a pipeline on the dltHub platform

Partner Integration

[dltHub](https://dlthub.com/) provides the agentic tools and managed ingestion infrastructure for any warehouse, including ClickHouse Cloud.
Teams and agents can build and operate data pipelines at scale, producing auditable data the whole organization can trust.

[ClickHouse Cloud](https://clickhouse.com/cloud) is a [destination supported by `dlt`](https://dlthub.com/docs/dlt-ecosystem/destinations/clickhouse), so you can replicate databases, load files, ingest from SaaS, or load from arbitrary REST APIs.

This tutorial shows how to deploy and schedule a pipeline on dltHub to load data into ClickHouse Cloud.

## Prerequisites

* Python >=3.11 and [uv](https://docs.astral.sh/uv/)
* [ClickHouse Cloud](https://clickhouse.com/cloud) account
* [dltHub](https://app.dlthub.com) account

**1. Gather your ClickHouse connection details**

To connect to ClickHouse with HTTP(S) you need this information:

| Parameter(s) | Description |
| - | - |
| `HOST` and `PORT` | Typically, the port is 8443 when using TLS or 8123 when not using TLS. |
| `DATABASE NAME` | Out of the box, there is a database named `default`, use the name of the database that you want to connect to. |
| `USERNAME` and `PASSWORD` | Out of the box, the username is `default`. Use the username appropriate for your use case. |

The details for your ClickHouse Cloud service are available in the ClickHouse Cloud console.
Select a service and click **Connect**:

![ClickHouse Cloud service connect button](https://mintcdn.com/private-7c7dfe99/EDr8ydtGBgFPOQea/images/_snippets/cloud-connect-button.webp?fit=max\&auto=format\&n=EDr8ydtGBgFPOQea\&q=85\&s=97d6a020a443f1b365b017488b39d0c8)

Choose **HTTPS**. Connection details are displayed in an example `curl` command.

![ClickHouse Cloud HTTPS connection details](https://mintcdn.com/private-7c7dfe99/EDr8ydtGBgFPOQea/images/_snippets/connection-details-https.webp?fit=max\&auto=format\&n=EDr8ydtGBgFPOQea\&q=85\&s=80369fc90cd1ac3108fe455f2426c19a)

If you're using self-managed ClickHouse, the connection details are set by your ClickHouse administrator.

dlt connects over both the native protocol and HTTP(S), so you also need the native port, which is `9440` (TLS). The HTTPS port is `8443`.

**2. Create a database and a user for dltHub**

Connect to ClickHouse with the [SQL console](https://clickhouse.com/docs/integrations/connectors/sql-clients/sql-console.md) and create a database and a dedicated user:

```sql theme={null}
CREATE DATABASE IF NOT EXISTS dlt;
CREATE USER dlt IDENTIFIED BY '<your-password>';
GRANT CREATE, ALTER, SELECT, INSERT, DELETE, DROP, TRUNCATE, OPTIMIZE, SHOW ON dlt.* TO dlt;
GRANT SELECT ON INFORMATION_SCHEMA.COLUMNS TO dlt;
GRANT CREATE TEMPORARY TABLE ON *.* TO dlt;
GRANT TABLE ENGINE ON * TO dlt;
```

**3. Create a dltHub workspace**

In an empty directory, run:

```bash theme={null}
uvx dlthub-start@latest
```

The command creates a workspace, installs its dependencies with `uv`, signs you in to dltHub, and configures a coding agent. Pick an agent when prompted. You can decline when it offers to launch it, because this tutorial doesn't need one.

> [!NOTE]
>
> To add dltHub to an existing dlt project instead, run `uvx dlthub-init@latest`. See [Install dltHub](https://dlthub.com/docs/hub/getting-started/installation).

Add the ClickHouse dependencies to the workspace:

```bash theme={null}
uv add "dlt[clickhouse]"
```

**4. Add a pipeline**

The workspace comes with a sample pipeline. Replace the contents of `pipeline.py` with a pipeline that loads issues and commits from the [GitHub REST API](https://docs.github.com/en/rest) for the `ClickHouse/ClickHouse` repository every hour:

```python theme={null}
import dlt
from dlt.hub import run
from dlt.hub.run import trigger
from dlt.sources.rest_api import rest_api_source


@run.pipeline("github_pipeline", trigger=trigger.schedule("0 * * * *"))
def load_github():
    source = rest_api_source(
        {
            "client": {
                "base_url": "https://api.github.com/repos/ClickHouse/ClickHouse/",
                "headers": {"Accept": "application/vnd.github+json"},
            },
            "resource_defaults": {"endpoint": {"params": {"per_page": 100}}},
            "resources": [
                {
                    "name": "issues",
                    "primary_key": "id",
                    "write_disposition": "merge",
                    "endpoint": {
                        "path": "issues",
                        "params": {
                            "state": "all",
                            "since": {
                                "type": "incremental",
                                "cursor_path": "updated_at",
                                "initial_value": "2026-11-30T00:00:00Z",
                            },
                        },
                    },
                },
                {
                    "name": "commits",
                    "primary_key": "sha",
                    "write_disposition": "merge",
                    "endpoint": {
                        "path": "commits",
                        "params": {
                            "since": {
                                "type": "incremental",
                                "cursor_path": "commit.committer.date",
                                "initial_value": "2026-11-30T00:00:00Z",
                            },
                        },
                    },
                },
            ],
        }
    )

    pipeline = dlt.pipeline(
        pipeline_name="github_pipeline",
        destination="clickhouse",
        dataset_name="github_data",
    )
    print(pipeline.run(source))
```

The pipeline loads only issues and commits updated since `initial_value`, then continues from the last cursor value on each run. Adjust `initial_value` to a recent date to keep the first load small. The GitHub API allows 60 unauthenticated requests per hour, and each page of 100 records is one request. See [GitHub rate limits](https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api).

The `trigger` schedules the job with a cron expression. See [triggers and scheduling](https://dlthub.com/docs/hub/pipeline-operations/triggers) for cron, intervals and follow-up jobs.

Then replace the contents of `__deployment__.py` to register the pipeline as a job that dltHub can deploy:

```python theme={null}
"""Loads GitHub issues and commits into ClickHouse."""

from pipeline import load_github

__all__ = ["load_github"]
```

**5. Set the ClickHouse credentials on dltHub**

dlt reads destination credentials from environment variables. Store them as [workspace variables](https://dlthub.com/docs/hub/command-line-interface) on dltHub, which injects them into every run. Secret values are write-only and never shown again.

```bash theme={null}
# REPLACE <PLACEHOLDER> VALUES
uv run dlthub variable set DESTINATION__CLICKHOUSE__CREDENTIALS__HOST --workspace --plain --value "<PLACEHOLDER>.clickhouse.cloud"
uv run dlthub variable set DESTINATION__CLICKHOUSE__CREDENTIALS__PORT --workspace --plain --value 9440
uv run dlthub variable set DESTINATION__CLICKHOUSE__CREDENTIALS__HTTP_PORT --workspace --plain --value 8443
uv run dlthub variable set DESTINATION__CLICKHOUSE__CREDENTIALS__SECURE --workspace --plain --value 1
uv run dlthub variable set DESTINATION__CLICKHOUSE__CREDENTIALS__DATABASE --workspace --plain --value dlt
uv run dlthub variable set DESTINATION__CLICKHOUSE__CREDENTIALS__USERNAME --workspace --plain --value dlt
uv run dlthub variable set DESTINATION__CLICKHOUSE__CREDENTIALS__PASSWORD --workspace --secret
```

The last command reads the password from stdin, so it doesn't end up in your shell history.

**6. Deploy and run the pipeline**

Deploy the workspace to dltHub. This syncs your code, registers the job and starts its hourly schedule:

```bash theme={null}
uv run dlthub deploy
```

Run the job right away and follow its logs until it finishes:

```bash theme={null}
uv run dlthub run load_github -f
```

To open the run and the workspace in the dltHub web app at [app.dlthub.com](https://app.dlthub.com/), run:

```bash theme={null}
uv run dlthub show
```

**7. Verify the data in ClickHouse**

You can use the web UI or the [`clickhousectl`](https://clickhouse.com/docs/concepts/features/connect-to-clickhouse/native-tools/clickhousectl) CLI to check the loaded data. Authenticate once with `clickhousectl cloud auth login`, then list the tables:

```bash theme={null}
clickhousectl cloud clickhouse query --name "<your-service-name>" -q "SHOW TABLES FROM dlt"
```

```response theme={null}
github_data____dlt_loads
github_data____dlt_pipeline_state
github_data____dlt_version
github_data___commits
github_data___commits__parents
github_data___dlt_sentinel_table
github_data___issues
github_data___issues__assignees
github_data___issues__labels
```

ClickHouse has no concept of a dataset, so dlt prefixes the table names with the dataset name (`github_data`) and the separator `___`. dlt flattens nested objects into columns such as `user__login` and `commit__author__name`, and unpacks nested lists into child tables such as `issues__labels` and `commits__parents`. The `_dlt_*` tables hold dlt's own metadata about loads, pipeline state and schema versions. See [Datasets](https://dlthub.com/docs/dlt-ecosystem/destinations/clickhouse#datasets) in the dlt documentation.

Check the status of the loads and the row count:

```bash theme={null}
clickhousectl cloud clickhouse query --name "<your-service-name>" -q "SELECT load_id, status FROM dlt.github_data____dlt_loads"
clickhousectl cloud clickhouse query --name "<your-service-name>" -q "SELECT count() FROM dlt.github_data___issues"
clickhousectl cloud clickhouse query --name "<your-service-name>" -q "SELECT number, state, title, user__login FROM dlt.github_data___issues ORDER BY created_at DESC LIMIT 5"
```

A `status` of `0` means the load completed successfully.

Congratulations! You've successfully created a pipeline that loads to ClickHouse Cloud and deployed it to dltHub.

## Next steps

* Replace the GitHub source with your own. Ask your coding agent to build one with the [dltHub AI Harness](https://dlthub.com/docs/hub/ai-harness/introduction), or use the [`rest_api`](https://dlthub.com/docs/dlt-ecosystem/verified-sources/rest_api/), [`sql_database`](https://dlthub.com/docs/dlt-ecosystem/verified-sources/sql_database/) or [`filesystem`](https://dlthub.com/docs/dlt-ecosystem/verified-sources/filesystem/) sources from dlt.
* Use [dltHub Ontology](https://dlthub.com/blog/dlthub-clickhouse-ontology-agents) to generate business context as data loads, for use by your ClickHouse agents.
