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.1.0.tar.gz (29.6 kB view details)

Uploaded Source

Built Distribution

aiochsa-1.1.0-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiochsa-1.1.0.tar.gz
  • Upload date:
  • Size: 29.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.5

File hashes

Hashes for aiochsa-1.1.0.tar.gz
Algorithm Hash digest
SHA256 0ac96e63c762a8d873af8c855285f03e253d0cab86a8ff3528e677df4b595566
MD5 4f132fd75426c717bc2686d366309f38
BLAKE2b-256 a4a464cf57bd75c72b56621dbc26996a3fe3d1bad1f402ae0bb837e04304c51f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aiochsa-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.5

File hashes

Hashes for aiochsa-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b9e3b96862be2543e60b196ea156a2615f46968ed262506bdb82bfcf53aa0027
MD5 8f2a46004c73b0b331ea45ff9d395391
BLAKE2b-256 ddbad6e2cf37940826d6897fbc1396d4b9961b164289f966053b32e37701ad96

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