Skip to main content

Clickhouse Python/asyncio library for use with SQLAlchemy core

Project description

Clickhouse Python/asyncio library for use with SQLAlchemy core

Example

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://127.0.0.1:8123') as conn:
    await conn.execute(
        table.insert(),
        [
            {'id': 1, 'name': 'Alice'},
            {'id': 2, 'name': 'Bob'},
        ],
    )
    rows = await conn.fetch(
        table.select()
    )

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

Configure logging to show SQL:

logging.getLogger('aiochsa.client.SQL').setLevel(logging.DEBUG)

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

See CHANGELOG.

Development

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

Running tests:

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

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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file aiochsa-1.2.2.tar.gz.

File metadata

  • Download URL: aiochsa-1.2.2.tar.gz
  • Upload date:
  • Size: 30.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for aiochsa-1.2.2.tar.gz
Algorithm Hash digest
SHA256 eecb3cfb354cd25cca50a15a96ecc29dee873c8f4986dd1553a72e1b823b6e1f
MD5 45ee5f708b30c7394bc11a9f895e98e9
BLAKE2b-256 df9c20f8af7b202f408720aebd75233d9ad92928e7b772cfd4419a32e2723a70

See more details on using hashes here.

File details

Details for the file aiochsa-1.2.2-py3-none-any.whl.

File metadata

  • Download URL: aiochsa-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 21.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for aiochsa-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8820dab192e23760f21442950f9a0a40283c8d6ec9cd0c06a73b28273cc31075
MD5 1424fbd0721387b80385f6c742c41c82
BLAKE2b-256 c65fe7d60ee0ec3caf99c7f490bc300059050faf0dba18d569ff25af1517482c

See more details on using hashes here.

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