# hypequery vs clickhouse-connect: Driver or Semantic Layer? (https://hypequery.com/compare/hypequery-vs-clickhouse-connect)

Updated: 2026-11-08

**Verdict:** clickhouse-connect is the official Python driver, and it runs the SQL you write. hypequery runs on top of it and adds shared measures, request validation, and tenant isolation. Use the driver for raw SQL and inserts, and hypequery for the numbers your product shares.

| | hypequery | clickhouse-connect |
|---|---|---|
| What it is | A semantic layer in Python, built on clickhouse-connect | The official ClickHouse Python driver |
| You write | Datasets: measures, dimensions, tenant key | SQL strings with server-side parameters |
| Tenant isolation | Added to every query; fails closed without a tenant | Your responsibility in each query |
| HTTP and agents | FastAPI endpoints, typed React hooks, MCP bridge | None; build your own API |
| Results | Rows as dicts with decimals and dates as strings; to_pandas(), to_polars() and to_arrow() for analysis | Native types, NumPy, pandas, and Arrow for any SQL |
| Inserts | Not supported; read-only queries | Fast bulk inserts |

## When to pick clickhouse-connect instead

- Inserts and ingestion: hypequery’s Python SDK is read-only.
- Schema changes, admin scripts and one-off SQL.
- Data science on arbitrary SQL, where query_df or query_arrow returns a DataFrame or Arrow table directly.
- A single script or notebook where shared measures, validation and tenant isolation add nothing.

clickhouse-connect is the official ClickHouse driver for Python. It sends SQL over HTTP, binds parameters on the server, and hands results back as Python values, NumPy arrays, pandas DataFrames, or Arrow tables. It also does fast bulk inserts. If you run ClickHouse from Python, you probably already use it.

hypequery is not a different driver. Its Python package runs on clickhouse-connect. What it adds sits above the driver: a definition of what your numbers mean, and rules about who may ask for them.

So this isn't really a choice between two tools. The question is whether your analytics SQL needs a layer on top.

## What clickhouse-connect gives you

- **Any SQL you can write.** Queries, DDL, inserts, settings, and system tables.
- **Server-side parameters.** Values are bound by ClickHouse, not interpolated into strings.
- **Data-science output.** `query_df` and `query_arrow` return DataFrames and Arrow tables directly.
- **Bulk inserts.** Columnar inserts and async inserts for ingestion.

It does not know what "revenue" means, which customer a request belongs to, or which fields a caller should be allowed to group by. That knowledge lives in your SQL strings.

## What hypequery adds

You describe a dataset once: its table, dimensions, measures, time column, and tenant key.

```python
from hypequery.datasets import Dataset, dimension, measure

orders = Dataset(
    name="orders",
    source="orders",
    tenant_key="org_id",
    time_key="created_at",
    dimensions={"status": dimension("string"), "country": dimension("string")},
    measures={"revenue": measure.sum("amount"), "order_count": measure.count("order_id")},
)
```

Callers then ask for measures by name:

```python
from hypequery.datasets import tenant

result = analytics.for_tenant(tenant("org_123")).execute(
    "orders", {"dimensions": ["country"], "measures": ["revenue"]}
)
```

hypequery plans the SQL, rejects fields the dataset doesn't declare, and adds the tenant filter. A query without a tenant fails instead of reading every customer. The same dataset can be served from FastAPI, consumed by generated React hooks, and exposed to AI agents through the MCP bridge.

## Where each one fits

Use **clickhouse-connect directly** for:

- inserts and ingestion
- schema changes and admin scripts
- one-off analysis where `query_df` on arbitrary SQL is exactly what you want

Use **hypequery** when:

- the same measure is queried from several places: an API, a job, a notebook, a dashboard
- customers see the results, so tenant isolation can't depend on each query remembering a filter
- you want HTTP endpoints, typed frontend hooks, or agent access without writing them by hand

## Trade-offs to know

hypequery returns rows as dictionaries, with decimals, dates, and timestamps as strings so nothing loses precision. That's the right default for APIs. For a notebook, `result.to_pandas()`, `to_polars()` and `to_arrow()` convert a dataset result with column types taken from the dataset definition. For arbitrary SQL that isn't a dataset, `query_df` on the driver is still the direct route.

hypequery is read-only. Inserts stay with the driver.

## Using both

They can share one client. `ClickHouseExecutor` accepts an existing clickhouse-connect client:

```python
import clickhouse_connect
from hypequery.datasets import create_dataset_client
from hypequery.execution import ClickHouseExecutor

from analytics.datasets import registry

client = clickhouse_connect.get_client(host="localhost", username="default", password="")
analytics = create_dataset_client(executor=ClickHouseExecutor(client), registry=registry)
```

Most teams end up with both: the driver for writing and exploring, hypequery for the numbers they share.

## FAQ

### Does hypequery replace clickhouse-connect?

No. hypequery uses clickhouse-connect to talk to ClickHouse. It replaces the analytics SQL you would otherwise write and maintain by hand, not the driver.

### When should I use clickhouse-connect directly?

For inserts, schema changes, one-off scripts, and data science work where you want `query_df` or Arrow output for arbitrary SQL. Use hypequery when the same measure is queried from several places or by customers.

### Can they share a connection?

Yes. `ClickHouseExecutor` accepts an existing clickhouse-connect client, so you can reuse one you already create.
