Open sourceApache 2.0

ClickHouse pandas

Get governed ClickHouse metrics into pandas, by name

Notebooks are where numbers drift. hypequery lets analysts query the same measures and dimensions your product and dashboards use, so a DataFrame of “revenue by month” matches what customers see.

Works in

Jupyter, scripts, jobs

Output

pandas, Polars, Arrow

Types

From your definitions

Every notebook has its own revenue

Analysts copy a SQL query from a dashboard, tweak it, and the number in the deck no longer matches the product.

Joins and filters get re-derived

Each analysis rediscovers which status counts as completed, which table holds refunds, and how to bucket by week.

Customer data needs a deliberate scope

A notebook that forgets the tenant filter silently mixes customers. Cross-customer analysis should be explicit.

Notebook

Query the definitions, not the tables

Import the datasets your application defines, query measures by name with a time grain, and call to_pandas().

  • Measures, filters, and relationships come from reviewed code
  • Time grains like by="month" produce a timezone-aware period column
  • to_polars() and to_arrow() work the same way
  • The same query runs in a scheduled job without changes

notebook

Revenue by month into a DataFrame

analysis.ipynb
# pip install "hypequery[clickhouse,pandas]==0.1.0b3"
from hypequery.datasets import create_dataset_client, tenant
from hypequery.execution import (
    ClickHouseConnection,
    create_clickhouse_executor,
)

from analytics.datasets import registry  # the definitions your app uses

analytics = create_dataset_client(
    executor=create_clickhouse_executor(ClickHouseConnection.from_env()),
    registry=registry,
)

result = analytics.for_tenant(tenant("org_123")).execute(
    "orders", {"measures": ["revenue", "order_count"], "by": "month"}
)

df = result.to_pandas()  # or result.to_polars(), result.to_arrow()

ClickHouseConnection.from_env() reads CLICKHOUSE_URL or the CLICKHOUSE_* variables.

Types and scope

Typed columns, from the definition

Each column’s type comes from the dataset, not from guessing at values: time buckets become datetimes in the query’s timezone, counts nullable integers, other measures floats. An empty result gets the same dtypes.

Pass decimals="decimal" to keep ClickHouse decimals exact. Integers beyond Int64 become unsigned or exact columns rather than overflowing.

Tenant-scoped datasets require a tenant. For internal analysis across every customer, pass all_tenants() explicitly so the intent is visible in the code.

notebook

Typed columns and cross-customer analysis

analysis.ipynb
df.dtypes
# period         datetime64[us, UTC]
# revenue                    float64
# order_count                  Int64

#                      period     revenue  order_count
# 0 2025-01-01 00:00:00+00:00  2876716.62         5693
# 1 2025-02-01 00:00:00+00:00  2486385.87         5028

# Keep ClickHouse decimals exact instead of floats:
result.to_pandas(decimals="decimal")

# Internal analysis across every customer has to say so explicitly:
from hypequery.datasets import ExecutionContext, all_tenants

analytics.execute(
    "orders",
    {"measures": ["revenue"], "by": "month"},
    context=ExecutionContext(tenant=all_tenants()),
).to_pandas()

Output shown from a sample orders table.

Where teams usually get stuck

Questions teams ask

ClickHouse to pandas DataFrame

Query measures through hypequery and call result.to_pandas() for typed columns.

Metrics layer for notebooks

Analysts and the product read the same definitions, so numbers match across decks and dashboards.

How do I load ClickHouse data into pandas?

With clickhouse-connect, client.query_df(sql) returns a pandas DataFrame and client.insert_df(table, df) writes one back. For a metric your product already defines, hypequery returns the same DataFrame by measure name instead of SQL.

clickhouse-connect query_df

clickhouse-connect returns DataFrames for raw SQL. hypequery returns them for named measures, with validation and tenancy.

Polars or Arrow?

result.to_polars() and result.to_arrow() use the same column types. Install hypequery[polars] or hypequery[arrow].

Next step

Rebuild one notebook query on a dataset

Pick the query behind your most-shared chart, define it as a dataset, and compare the numbers.

Open source, and it runs in your own backend. Want it hosted?

Get early access to hypequery cloud.

Cloud hosts the same model you run in your backend, with a managed API and MCP server, versions, and rollback. We're letting teams in a few at a time. Join the waitlist and we'll reach out when your project can go live.

How do you want to build your analytics layer? (Optional)
What features do you most need? (Optional)

Pick as many as you like.

Only your email is required. All other questions are optional.