chquery: Async ClickHouse Python Client
chquery is an async Python client and query builder for ClickHouse, built on top of asynch. It provides a simple, high-level API for querying ClickHouse asynchronously, with a convenient query builder. Used by myself for most of my data analytics since the beginning of 2025.
Features
- Async connection pool management
- High-level query builder (select, filters, order, limit, insert, etc.)
- Raw SQL execution
- Custom error handling
- Batch insert and async iteration for large result sets
- Type hints and docstrings for easy development
Installation
Install chquery:
pip install git+https://github.com/filipnyquist/chquery.git
Usage Example
import asyncio
from chquery import CHDriver, DbError
async def main():
driver = CHDriver(dsn="clickhouse://user:pass@localhost/default")
await driver.startup()
try:
# Simple query
rows = await driver.fetch_all("SELECT * FROM my_table LIMIT 10")
print(rows)
# Using the query builder
qb = driver.qb("my_table").fields(["id", "name"]).filters({"id[gt]": 10}).order_by(["-id"]).limit(5)
results = await qb.all()
print(results)
# Insert data
await driver.qb("my_table").insert({"id": 123, "name": "Alice"})
# Check if a row exists
exists = await driver.qb("my_table").filters({"id[eq]": 123}).exists()
print("Exists:", exists)
# Count rows
count = await driver.qb("my_table").count()
print("Count:", count)
# Async iteration for large results
async for row in driver.qb("my_table").all_iter(batch_size=100):
print(row)
except DbError as e:
print("Database error:", e)
finally:
await driver.shutdown()
asyncio.run(main())
API Overview
CHDriver
startup()/shutdown()/close()fetch_all(query, *args)/fetch_one(query, *args)insert_many(query, data)raw(query, *args, fetch='all')ping()qb(table)— returns aCHQueryBuilder
CHQueryBuilder
fields(list)filters(dict)— supports[eq],[ne],[lt],[lte],[gt],[gte],[in],[like],[isnull]order_by(list)limit(n)/offset(n)all()/one()/count()/exists()all_iter(batch_size=1000)— async generatorinsert(data)reset()
License
MIT
Metadata
Release files for chquery 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| chquery-0.0.2.tar.gz | 9.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| chquery-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.1 kB
Release files / chquery-0.0.2.tar.gz
| Download URL | chquery-0.0.2.tar.gz |
|---|---|
| Size | 9.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
621fdd20caf60c2760e551c4d938e543b5a07a53f1036ece4f0e66996fd0eaf9
|
|
BLAKE2b-256 checksum How to use checksums |
fa0c4694a12d34c7e4fe89faad088868473be7b220c944997d289fd5c529ab39
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 10, 2025.
Transparency logRelease files / chquery-0.0.2-py3-none-any.whl
| Download URL | chquery-0.0.2-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f9c6ef1732374d0d3ad3fd364dad9706d9680e7bf336ca29c69885a4654e139c
|
|
BLAKE2b-256 checksum How to use checksums |
11ccdaf9b372ae938f472b712baf2f44bd6ae47430183e77e73a2bbdd45ab62c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 10, 2025.
Transparency log