Skip to main content

CHQuery is an async Python client and query builder for ClickHouse, built on top of asynch using native TCP connection for speed.

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 a CHQueryBuilder

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 generator
  • insert(data)
  • reset()

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chquery-0.0.2.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chquery-0.0.2-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file chquery-0.0.2.tar.gz.

File metadata

  • Download URL: chquery-0.0.2.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for chquery-0.0.2.tar.gz
Algorithm Hash digest
SHA256 621fdd20caf60c2760e551c4d938e543b5a07a53f1036ece4f0e66996fd0eaf9
MD5 6542036310c8967543dbaf5f4626dc6a
BLAKE2b-256 fa0c4694a12d34c7e4fe89faad088868473be7b220c944997d289fd5c529ab39

See more details on using hashes here.

Provenance

The following attestation bundles were made for chquery-0.0.2.tar.gz:

Publisher: dist.yml on filipnyquist/chquery

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file chquery-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: chquery-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for chquery-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f9c6ef1732374d0d3ad3fd364dad9706d9680e7bf336ca29c69885a4654e139c
MD5 7c594ddf31335391cacc36896e5ef398
BLAKE2b-256 11ccdaf9b372ae938f472b712baf2f44bd6ae47430183e77e73a2bbdd45ab62c

See more details on using hashes here.

Provenance

The following attestation bundles were made for chquery-0.0.2-py3-none-any.whl:

Publisher: dist.yml on filipnyquist/chquery

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page