Skip to main content

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 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.1.tar.gz (8.8 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.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

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

Hashes for chquery-0.0.1.tar.gz
Algorithm Hash digest
SHA256 3bef71ed8c07cbc6ace786963ea5c147b18fdb2b8a2051323c4579b618606464
MD5 4a8f13f229d1a0adda1568e3ef6ce538
BLAKE2b-256 85aee57c103e035fa0141ef24db82149f379da99d227477fa28d12ea2a909b55

See more details on using hashes here.

Provenance

The following attestation bundles were made for chquery-0.0.1.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.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

Hashes for chquery-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c0ee3e5b4cc1aab5f67ff00db5b7c58d54418eae08158704642a10ad65cde53a
MD5 9e17dd7e0240df13c03179e5dd07795a
BLAKE2b-256 ed29e9ed3a71bc7e75fdf439f27313105598ddc830d9c210c09b5ac9a9a3574e

See more details on using hashes here.

Provenance

The following attestation bundles were made for chquery-0.0.1-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