ClickHouse Python clients
ClickHouse Python clients compared: clickhouse-connect, clickhouse-driver, SQLAlchemy and hypequery
For most Python code, use clickhouse-connect: it is the client ClickHouse maintains, it talks to the HTTP interface, binds {name:Type} parameters on the server, and returns pandas, NumPy or Arrow. clickhouse-driver is the community client for the native TCP protocol, clickhouse-sqlalchemy is a SQLAlchemy dialect built on it, and hypequery runs on top of clickhouse-connect to add named, validated, tenant-scoped analytics queries.
Official client
clickhouse-connect 1.12.0
Native TCP client
clickhouse-driver 0.2.11
Examples checked on
ClickHouse 26.6, Python 3.13
Comparison
clickhouse-connect vs clickhouse-driver vs clickhouse-sqlalchemy vs hypequery
The first three are ways to send SQL to ClickHouse. hypequery is a layer above clickhouse-connect: you declare measures and dimensions, and it writes the SQL.
| clickhouse-connect | clickhouse-driver | clickhouse-sqlalchemy | hypequery | |
|---|---|---|---|---|
| Maintained by | ClickHouse, in the ClickHouse/clickhouse-connect GitHub repository | Community, mymarilyn/clickhouse-driver | Community, xzkostyan/clickhouse-sqlalchemy | hypequery, Apache-2.0 |
| Protocol | HTTP interface, port 8123 by default | Native TCP protocol, port 9000 by default | Native through clickhouse-driver (the interface its README recommends), HTTP, or async native through asynch | HTTP, through clickhouse-connect |
| Latest release on PyPI | 1.12.0, 3 Nov 2026 | 0.2.11, 17 Jul 2026 | 0.3.2, 12 Jun 2024 | 0.1.0b4, 10 Nov 2026 (beta) |
| Python | 3.10 to 3.15 | 3.9 and later | 3.7 and later, with SQLAlchemy 2.0.x | 3.11 and later |
| Query parameters | Server-side {name:Type} placeholders, or client-side %(name)s formatting | Client-side %(name)s escaping by default; server-side {name:Type} with server_side_params=True | SQLAlchemy bound parameters from expressions or text() | Generated: every value is sent as a server-side parameter |
| DataFrames and Arrow | query_df, query_np, query_arrow, insert_df; Polars through query_df_arrow | query_dataframe with the use_numpy setting and the numpy extra | Rows through SQLAlchemy result objects | to_pandas(), to_polars(), to_arrow(), typed from the dataset |
| asyncio | get_async_client, with clickhouse-connect[async] | No async API; asynch is a separate async native client | clickhouse+asynch:// through asynch | create_async_dataset_client |
| SQLAlchemy | Its own clickhousedb:// dialect: Core, reflection and basic ORM reads | Used by clickhouse-sqlalchemy as its native transport | The dialect itself: Core, ORM sessions and ClickHouse table engines | executor_from_engine reuses an HTTP engine URL |
| Use it for | New code, notebooks, inserts, Superset | Code already written against it, or networks that only open the native port | Apps whose models already live in SQLAlchemy | Metrics that more than one service, API or agent reads |
Releases and Python ranges from PyPI, rechecked on 14 November 2026. Every example on this page ran against ClickHouse 26.6.2 on Python 3.13 with clickhouse-connect 1.12.0, clickhouse-driver 0.2.11, clickhouse-sqlalchemy 0.3.2 and hypequery 0.1.0b3.
The clients
Which ClickHouse Python client should you use?
All of these talk to the same server. The choice depends on which protocol you can reach and which API your code already uses.
clickhouse-connect
The client ClickHouse maintains, and the one its Python docs describe. It uses the HTTP interface and binds {name:Type} parameters on the server. query_df, query_np and query_arrow return pandas, NumPy and Arrow, and insert_df writes a DataFrame. Start here for new code.
clickhouse-driver
A community client for the native TCP protocol, still released (0.2.11 in July 2026). It escapes %(name)s values into the SQL in Python by default, and binds them on the server with server_side_params=True. Choose it when existing code depends on it or only the native port is reachable.
clickhouse-sqlalchemy
A SQLAlchemy 2.0 dialect with Core, ORM sessions and ClickHouse engines such as engines.MergeTree. Its README recommends the native transport through clickhouse-driver, with HTTP and asynch as alternatives. The last release, 0.3.2, is from June 2024. Choose it when your models already live in SQLAlchemy.
clickhouse-connect's SQLAlchemy dialect
clickhouse-connect registers its own clickhousedb:// dialect over HTTP. ClickHouse documents it as supporting Core, reflection and Alembic, with basic ORM reads and inserts, and recommends it for Apache Superset.
chDB
chDB runs the ClickHouse engine inside your Python process, with no server to install. It reads Parquet, CSV, JSON and Arrow files and works with pandas, which suits notebooks and tests. clickhouse-connect can also use it through an experimental interface="chdb" backend.
hypequery
A semantic layer that runs on clickhouse-connect. You declare a table's dimensions and measures once, callers ask for them by name, and hypequery writes parameterized SQL, checks every filter against the declared fields and adds the tenant predicate. Use it next to a client, for the queries other code depends on.
Basics
The same query in clickhouse-connect, clickhouse-driver and SQLAlchemy
Each panel computes revenue per country for completed orders on the six-row orders table created in the first panel. The comments show what each one printed, wrapped to fit.
All three return the same rows. The Decimal(12, 2) sums differ in form: clickhouse-connect returned Decimal('1119.00') with the column's scale, while clickhouse-driver, and clickhouse-sqlalchemy on top of it, returned Decimal('1119').
clickhouse-sqlalchemy's ORM works too: session.query(...) on a declarative model from get_declarative_base() ran the same aggregation through make_session(engine).
Test data
A small multi-tenant orders table
Two tenants, acme and globex, so the injection test later can show one reading the other's rows.
clickhouse-connect
HTTP, server-side parameters, a DataFrame
parameters= with a {status:String} placeholder sends the value separately from the SQL. query_df returns a pandas DataFrame.
clickhouse-driver
Native TCP, client-side or server-side parameters
By default the driver escapes the value into the SQL text. With server_side_params=True it sends {name:Type} placeholders for the server to bind.
clickhouse-sqlalchemy
SQLAlchemy Core over the native protocol
clickhouse+native:// uses clickhouse-driver underneath; clickhouse+http:// uses HTTP instead.
Dynamic queries
Safely composing dynamic queries and filters in Python
Never paste user input into the SQL text with f-strings, + or %. Send each value as a server-side parameter ({name:Type} placeholders with parameters= in clickhouse-connect), add a clause only when its filter is present, and map anything that can't be a parameter, such as a sort column or ASC/DESC, through a dict of fixed SQL.
The first panel builds the WHERE clause with an f-string. Passing x' OR tenant_id != ' as the status produces tenant_id = 'acme' AND status = 'x' OR tenant_id != ''. AND binds tighter than OR, so every row matches and the call returns all six orders, including the two that belong to globex.
The second panel appends a clause and a parameter only for the filters the caller sent. An IN list binds as one Array(String) parameter and the amount as Decimal(12, 2). The same payload now returns [], because ClickHouse compares the whole string to status. On the wire, clickhouse-connect sent the SQL with {status:String} in the request body and the value as a separate param_status URL parameter.
Parameters hold values only. ClickHouse also has an Identifier parameter type for names (ORDER BY {col:Identifier}); it quotes the name, so amount; DROP TABLE orders failed with UNKNOWN_IDENTIFIER in our test. It still lets a caller sort by any column, and ASC/DESC can't be bound at all, so an allow-list is the simpler rule.
clickhouse-connect's client-side %(name)s binding and clickhouse-driver's default binding both escaped the same payload and returned 0 rows. What breaks is building the SQL string yourself. Server-side binding also keeps the value out of the query text, where it can't change how the query parses.
Unsafe
An f-string WHERE clause that leaks another tenant's rows
Run against a local test server. The second call returns globex orders to an acme caller.
Safe with clickhouse-connect
Optional filters, an IN list and an allow-listed sort
Only fixed strings from this file reach the SQL text. Every value from the caller travels as a typed parameter.
Dynamic queries with hypequery
The same filters with hypequery, validated against declared dimensions
With hypequery you pass filters as data (filter.eq, filter.in_list) against a dataset. Any field the dataset doesn't declare is rejected before a query runs, and the tenant comes from the execution context, so no filter can change it.
The injection payload returned (): hypequery sent it as {p0:String} and the tenant as {p1:String}, both server-side parameters.
validate checks a query without running it. Filtering on amount, which isn't a declared dimension, filtering on the tenant column, and sorting by a field the query doesn't select each came back invalid with the messages shown. A malformed field name fails earlier, when order.desc builds the value.
to_sql prints a redacted statement with <p0:Array(String)> where the values go. It is for debugging and can't be executed.
hypequery
A dataset and optional filters
Revenue comes back as a string to keep Decimal precision; to_pandas() turns it into a number column.
Validation
Undeclared fields and tenant filters are rejected
Continues the previous panel. validate and to_sql plan the query in Python and sent no request to ClickHouse.
hypequery on top
How hypequery uses clickhouse-connect
hypequery for Python runs its ClickHouse queries through clickhouse-connect. The hypequery[clickhouse] extra installs clickhouse-connect 1.4.2 or newer, and the executor opens one clickhouse-connect client for queries and a second for cancelling them with KILL QUERY.
Plain pip install hypequery installs only pydantic, tzdata, anyio and idna, so dataset definitions import without a database driver. Install hypequery[clickhouse], or hypequery[clickhouse-async] for asyncio, to execute queries.
The capture in the panel shows the request: the user agent is clickhouse-connect/1.12.0, the body holds the generated SQL with {p0:String} and {p1:String}, and the values travel as param_p0 and param_p1.
Keep calling clickhouse-connect directly for inserts, DDL and one-off SQL. Use hypequery for the measures several services read, so they share one definition and one tenant rule.
An existing SQLAlchemy engine works too: executor_from_engine(engine) accepted clickhousedb:// and clickhouse+http:// engines and refused clickhouse+native://, because server-side parameters need the HTTP interface.
On the wire
What hypequery sends through clickhouse-connect
Continues the hypequery panel above. Output trimmed to the request line, user agent and body.
Where teams usually get stuck
Questions teams ask
Should I use clickhouse-connect or clickhouse-driver?
clickhouse-connect is maintained by ClickHouse and uses the HTTP interface; clickhouse-driver is a community client for the native TCP protocol. Both returned the same rows in our tests and both escaped the injection payload. Pick clickhouse-connect for new code, for its {name:Type} server-side binding and its pandas, NumPy and Arrow methods. Keep clickhouse-driver where code or network rules already depend on the native protocol.
What is the best Python client for ClickHouse?
clickhouse-connect, for most projects: ClickHouse maintains it, its docs use it, and it shipped 1.12.0 on 3 November 2026. Use clickhouse-sqlalchemy if your app is built on SQLAlchemy, chDB to run ClickHouse in-process without a server, and add hypequery when several parts of your product query the same metrics.
Does ClickHouse work with SQLAlchemy?
Yes, through two dialects. clickhouse-sqlalchemy (clickhouse+native://, clickhouse+http://, clickhouse+asynch://) supports Core and ORM sessions and needs SQLAlchemy 2.0.x; its last release was 0.3.2 in June 2024. clickhouse-connect ships clickhousedb://, aimed at Core and Superset. Both ran a text() query with a bound parameter in our tests.
How do I build a ClickHouse WHERE clause from user input in Python?
Keep a list of clauses and a dict of parameters. For each filter the user sent, append a clause such as "status = {status:String}" and set params["status"]. Join the clauses with AND, map sort columns and directions through a dict of fixed SQL, and pass parameters=params to client.query.
Is clickhouse-driver still maintained?
Yes, as of November 2026: 0.2.11 reached PyPI on 17 July 2026 and the GitHub repository is not archived. It is a community project, separate from ClickHouse's own clickhouse-connect.
How do I get ClickHouse results into pandas?
With clickhouse-connect, client.query_df(sql) returns a DataFrame and client.insert_df(table, df) writes one. clickhouse-driver has query_dataframe when use_numpy is on. hypequery results have to_pandas(), which types columns from the dataset definition.
Sources
Examples
Runnable examples
Every example runs against the same seeded ClickHouse dataset. Scaffold one with npx @hypequery/cli create <slug> -y, or browse the full list.
Example · Python
Embedded ClickHouse analytics with chDB: typed datasets, a CLI and an API, no server
Run a ClickHouse semantic layer inside your Python process with chDB: no Docker, no server, then point the same datasets at ClickHouse Cloud.
Open example
Guide · ClickHouse 25.8
ClickHouse with Docker Compose: a pinned, persistent local server with a million-row sample dataset
Run ClickHouse 25.8 in Docker Compose with a healthcheck, a password, volumes and a 1M-row sample dataset, then connect from Node, Python and hypequery.
Open guide
Example · Python
Django analytics on ClickHouse: ORM for app data, typed datasets for metrics
Keep your Django models in SQLite or Postgres and serve ClickHouse analytics from typed hypequery datasets, scoped to request.user's organization.
Open example
Example · Python
A FastAPI analytics API on ClickHouse with tenant-scoped datasets
Serve governed ClickHouse analytics from FastAPI: datasets defined once in Python, query endpoints mounted beside your routes, tenant fixed by the token.
Open example
Example · Python
A governed Streamlit dashboard on ClickHouse with pandas export
Build a Streamlit dashboard on ClickHouse that reads only typed hypequery datasets: filters, a time series, breakdowns and a pandas CSV export.
Open example
Further reading
Go deeper where it actually helps
chDB Python tutorial
Run ClickHouse SQL inside a Python process, with no server.
Open guide
hypequery Python docs
Datasets, filters, execution and serving on top of clickhouse-connect.
Open guide
ClickHouse FastAPI
Serve Python datasets as authenticated, tenant-scoped HTTP endpoints.
Open guide
ClickHouse with Django
Query ClickHouse from a Django app next to your existing database.
Open guide
FastAPI and React analytics
Typed React hooks on the endpoints your Python app serves.
Open guide
Python semantic layer
Why define analytics as Python code instead of YAML or a separate server.
Open guide
Next step
Keep your client and model one table
Pick the ClickHouse query your services copy most often, define it as a dataset, and run it through the same clickhouse-connect connection settings you use today.
Open source, and it runs in your own backend. Want it hosted?