A wrapper around the asynch library for clickhouse
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file chquery-0.0.1.tar.gz.
File metadata
- Download URL: chquery-0.0.1.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3bef71ed8c07cbc6ace786963ea5c147b18fdb2b8a2051323c4579b618606464
|
|
| MD5 |
4a8f13f229d1a0adda1568e3ef6ce538
|
|
| BLAKE2b-256 |
85aee57c103e035fa0141ef24db82149f379da99d227477fa28d12ea2a909b55
|
Provenance
The following attestation bundles were made for chquery-0.0.1.tar.gz:
Publisher:
dist.yml on filipnyquist/chquery
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
chquery-0.0.1.tar.gz -
Subject digest:
3bef71ed8c07cbc6ace786963ea5c147b18fdb2b8a2051323c4579b618606464 - Sigstore transparency entry: 233821010
- Sigstore integration time:
-
Permalink:
filipnyquist/chquery@c02b74797a1f6986155edfe55dd73b95685cc62e -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/filipnyquist
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
dist.yml@c02b74797a1f6986155edfe55dd73b95685cc62e -
Trigger Event:
push
-
Statement type:
File details
Details for the file chquery-0.0.1-py3-none-any.whl.
File metadata
- Download URL: chquery-0.0.1-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0ee3e5b4cc1aab5f67ff00db5b7c58d54418eae08158704642a10ad65cde53a
|
|
| MD5 |
9e17dd7e0240df13c03179e5dd07795a
|
|
| BLAKE2b-256 |
ed29e9ed3a71bc7e75fdf439f27313105598ddc830d9c210c09b5ac9a9a3574e
|
Provenance
The following attestation bundles were made for chquery-0.0.1-py3-none-any.whl:
Publisher:
dist.yml on filipnyquist/chquery
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
chquery-0.0.1-py3-none-any.whl -
Subject digest:
c0ee3e5b4cc1aab5f67ff00db5b7c58d54418eae08158704642a10ad65cde53a - Sigstore transparency entry: 233821014
- Sigstore integration time:
-
Permalink:
filipnyquist/chquery@c02b74797a1f6986155edfe55dd73b95685cc62e -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/filipnyquist
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
dist.yml@c02b74797a1f6986155edfe55dd73b95685cc62e -
Trigger Event:
push
-
Statement type: