Skip to main content

Clickhouse Python/asyncio library for use with SQLAlchemy core

Project description

Clickhouse Python/asyncio library for use with SQLAlchemy core


import aiochsa
import sqlalchemy as sa

table = sa.Table(
    'test', sa.MetaData(),
    sa.Column('id', sa.Integer),
    sa.Column('name', sa.String),

async with aiochsa.connect('clickhouse://') as conn:
    await conn.execute(
            {'id': 1, 'name': 'Alice'},
            {'id': 2, 'name': 'Bob'},
    rows = await conn.fetch(

To add FINAL modifier use with_hint(table, 'FINAL') (see SQLAlchemy docs for details).

Configure logging to show SQL:


Custom type converters

Here is an example of installing converter for ClickHouse’s DateTime type that requires and returns timezone-aware Python’s datetime object and stores it as UTC:

from datetime import datetime
import aiochsa
from aiochsa.types import DateTimeUTCType, TypeRegistry

types = TypeRegistry()
types.register(DateTimeUTCType, ['DateTime'], datetime)
conn = aiochsa.connect(dsn, types=types)

Change log



Prerequizites: Python (use pyenv to manage multiple versions), pip, tox, coverage, docker, docker-compose.

Running tests:

# Run whole tests matrix:
# Run test with specific Python version only:
tox -e py38
# Test with specific Clickhouse version:
tox -e py38 -- --clickhouse-version=
# Run specified test(s):
tox -e py38 -- tests/

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

aiochsa-1.2.2.tar.gz (30.6 kB view hashes)

Uploaded source

Built Distribution

aiochsa-1.2.2-py3-none-any.whl (21.4 kB view hashes)

Uploaded py3

Supported by

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