Skip to main content

aioch2

aioch2 is a library for accessing a ClickHouse database over native interface from the asyncio. It wraps features of clickhouse-driver for asynchronous usage.

Installation

The package can be installed using pip:

pip install aioch2

Usage

from datetime import datetime

import asyncio
from aioch2 import Client


async def exec_progress():
    client = Client('localhost')

    progress = await client.execute_with_progress('LONG AND COMPLICATED QUERY')
    timeout = 20
    started_at = datetime.now()

    async for num_rows, total_rows in progress:
        done = num_rows / total_rows if total_rows else total_rows
        now = datetime.now()
        # Cancel query if it takes more than 20 seconds to process 50% of rows.
        if (now - started_at).total_seconds() > timeout and done < 0.5:
            await client.cancel()
            break
    else:
        rv = await progress.get_result()
        print(rv)


async def exec_no_progress():
    client = Client('localhost')
    rv = await client.execute('LONG AND COMPLICATED QUERY')
    print(rv)


loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait([exec_progress(), exec_no_progress()]))

For more information see clickhouse-driver usage examples.

Parameters

  • executor - instance of custom Executor, if not supplied default executor will be used
  • loop - asyncio compatible event loop

Other parameters are passing to wrapped clickhouse-driver's Client.

License

aioch2 is distributed under the MIT license.

Release files for aioch2 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aioch2 0.0.4
File Size Uploaded
aioch2-0.0.4.tar.gz 4.5 kB Details

Release files / aioch2-0.0.4.tar.gz

Download URL aioch2-0.0.4.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a670d0409daac80f62aa6213844fd3c43db9cd5e90a2ba76eac0fbd4bbe66b59
BLAKE2b-256 checksum
How to use checksums
7caecbd0f43f5b9ac036c7c5d8394a944f25b1e7e4459b96addb5d1859397aa1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.6.0 importlib_metadata/3.10.0 pkginfo/1.8.0 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.8

Release history Release notifications | RSS feed

This release

0.0.4 This release

1 release file

0.0.3

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page