Skip to main content

Library for accessing a ClickHouse database over native interface from the asyncio

Project description

aioch

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

Coverage Status Build Status

Installation

The package can be installed using pip:

pip install aioch

To install from source:

git clone https://github.com/mymarilyn/aioch
cd aioch
python setup.py install

Usage

from datetime import datetime

import asyncio
from aioch 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

aioch is distributed under the MIT license.

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

aioch2-0.0.3.tar.gz (4.7 kB view details)

Uploaded Source

File details

Details for the file aioch2-0.0.3.tar.gz.

File metadata

  • Download URL: aioch2-0.0.3.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for aioch2-0.0.3.tar.gz
Algorithm Hash digest
SHA256 c1a022f723d94e0ffa7938bda293a46fcf41dc912b615bab5a85e2ba8b193078
MD5 902025f6bd20b969e1bdb9f13d45064d
BLAKE2b-256 d78301182dac0e0fc9be6e897d4fa9c8bfaab3a5d01666444a413d9c995f4a24

See more details on using hashes here.

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