clickhouse_core
Shared ClickHouse connectivity library for Analytic AI services.
What it does
- Creates ClickHouse clients using a single config model.
- Supports both TCP (clickhouse-driver) and HTTP (clickhouse-connect).
- Provides sync and async APIs with consistent return types.
- Normalizes query results to list-of-dict rows.
- Supports per-database pooled clients via a dbPoolMap.
- Logs client creation and query execution.
Install
pip install -r requirements.txt
Usage (TCP)
from clickhouse_core import ClickHouseConfig, get_client
config = ClickHouseConfig(host="clickhouse", port=9000, database="default")
client = get_client(config)
rows = client.fetch_all("SELECT 1 AS one")
Usage (HTTP)
from clickhouse_core import ClickHouseConfig, get_client
config = ClickHouseConfig(host="clickhouse", port=8123, database="default", protocol="http")
client = get_client(config)
rows = client.fetch_all("SELECT 1 AS one")
Async usage
from clickhouse_core import ClickHouseConfig, get_async_client
config = ClickHouseConfig(host="clickhouse", port=9000, database="default")
client = get_async_client(config)
rows = await client.fetch_all("SELECT 1 AS one")
Pool manager (dbPoolMap)
from libs.clickhouse_core import ClickHouseConfig, ClickHousePoolFactory
base_config = ClickHouseConfig.from_env()
db_pool_map = {"default": 2, "analytics": 5}
pool = ClickHousePoolFactory(base_config, db_pool_map).build()
client = pool.get_client("default")
rows = client.fetch_all("SELECT 1")
async_client = pool.get_async_client("analytics")
rows = await async_client.fetch_all("SELECT 1")
Connection checks and per-DB credentials
- For each DB in
dbPoolMap, the pool manager checks connectivity once (usingSELECT 1). - If connection fails, that DB is skipped and a warning is logged.
- Per-DB env overrides are supported:
<DBNAME>_USERNAME
<DBNAME>_PASSWORD
If these are not set, the library falls back to CLICKHOUSE_USERNAME and
CLICKHOUSE_PASSWORD from the base config.
By default, on-demand clients are allowed for DBs not in dbPoolMap.
You can disable this by passing allow_on_demand=False to
ClickHousePoolFactory(...).
Configuration
Environment variables supported (prefix CLICKHOUSE_):
CLICKHOUSE_HOSTCLICKHOUSE_PORTCLICKHOUSE_DATABASECLICKHOUSE_USERNAMECLICKHOUSE_PASSWORDCLICKHOUSE_PROTOCOL(tcp|http)CLICKHOUSE_SECURE(true/false)CLICKHOUSE_CONNECT_TIMEOUTCLICKHOUSE_SEND_RECEIVE_TIMEOUTCLICKHOUSE_HTTP_VERIFYCLICKHOUSE_COMPRESSIONCLICKHOUSE_LOG_NAME
Logging
The library uses Python's standard logging. Configure logging in your service to see
client creation and query events. The logger name is taken from CLICKHOUSE_LOG_NAME
or defaults to clickhouse_core.
Versioning
See RELEASE.md for the git tag workflow and version bump rules.
Helper scripts:
python scripts/bump_clickhouse_core_version.py patch
python scripts/build_clickhouse_core.py
Build & install (real package)
From libs/clickhouse_core:
python -m pip install --upgrade build
python -m build
Install locally:
pip install dist/clickhouse_core-0.1.0-py3-none-any.whl
Install with HTTP support:
pip install dist/clickhouse_core-0.1.0-py3-none-any.whl[http]
Protected build (Cython .pyd inside wheel)
Set the environment variable before building:
set CLICKHOUSE_CORE_CYTHONIZE=1
python -m build
This produces a platform-specific wheel (e.g., cp312-win_amd64) containing .pyd files.
Monorepo usage
If you are using the library directly from this repo (not installed as a package):
from libs.clickhouse_core import ClickHouseConfig, get_client
Metadata
Release files for clickhouse-core 0.2.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| clickhouse_core-0.2.5.tar.gz | 24.7 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| clickhouse_core-0.2.5-cp311-cp311-win_amd64.whl | CPython 3.11 | CPython 3.11 | Windows x86-64 | Details |
| clickhouse_core-0.2.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.11 | CPython 3.11 | Linux glibc 2.17+ x86-64 | Details |
| clickhouse_core-0.2.5-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl | CPython 3.11 | CPython 3.11 | Linux glibc 2.5+ x86-32, Linux glibc 2.17+ x86-32 | Details |
| clickhouse_core-0.2.5-cp311-cp311-macosx_11_0_arm64.whl | CPython 3.11 | CPython 3.11 | macOS 11.0+ ARM64 | Details |
| clickhouse_core-0.2.5-cp311-cp311-macosx_10_9_x86_64.whl | CPython 3.11 | CPython 3.11 | macOS 10.9+ x86-64 | Details |
Total release size: 3.7 MB
Release files / clickhouse_core-0.2.5.tar.gz
| Download URL | clickhouse_core-0.2.5.tar.gz |
|---|---|
| Size | 24.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
59b8e22337d19a36b4c082132e6d1f3d4b8916bb62c0c8a8b59cb24453a3ac25
|
|
BLAKE2b-256 checksum How to use checksums |
36d71eb4f6cd9697a442a7ced66e0cdda143a8c82e905cf76aa7bf8a840c3e8b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 9, 2026.
Transparency logRelease files / clickhouse_core-0.2.5-cp311-cp311-win_amd64.whl
| Download URL | clickhouse_core-0.2.5-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 240.4 kB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
a5051decf4445a33d8841e1d2329035a712e3eeb36c696a5044f3ef9a684fc2b
|
|
BLAKE2b-256 checksum How to use checksums |
fb471c24b8a1c0ad26101643d58783287f73ecbdebfdb58d7d3fd508683ff229
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 9, 2026.
Transparency logRelease files / clickhouse_core-0.2.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | clickhouse_core-0.2.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
c9dfc687e1b00241306b38801edce33c0a5c793aaae9c43586a59040f21e240d
|
|
BLAKE2b-256 checksum How to use checksums |
9fb8df269e0791dfd87ae4b11cfd385f9d8f6531f4d8afbf86064e7828a4a940
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 9, 2026.
Transparency logRelease files / clickhouse_core-0.2.5-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
| Download URL | clickhouse_core-0.2.5-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl |
|---|---|
| Size | 1.4 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-32 Linux glibc 2.5+ x86-32 |
|
SHA-256 checksum How to use checksums |
dffa88fc497819aabc6a8d05a05d8f9b7f428b6c62a18aa19a734b1bf923a345
|
|
BLAKE2b-256 checksum How to use checksums |
cc54d37c63a826faf20b0547659578ae7a1c5a3547763c79b9c765e2f2351602
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 9, 2026.
Transparency logRelease files / clickhouse_core-0.2.5-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | clickhouse_core-0.2.5-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 261.9 kB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
f1de1e51503bb9c45e774e78b5358b1155a5fdccf351b8ca8787d951152925da
|
|
BLAKE2b-256 checksum How to use checksums |
4a9cfdef84db94211932d983f408713618016a24921e57a59b4cdef7aeaa787c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 9, 2026.
Transparency logRelease files / clickhouse_core-0.2.5-cp311-cp311-macosx_10_9_x86_64.whl
| Download URL | clickhouse_core-0.2.5-cp311-cp311-macosx_10_9_x86_64.whl |
|---|---|
| Size | 264.1 kB |
| Tags | CPython 3.11 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
aa29f6f5dc4ae58e312204670644d17106ff86f5c61fd6b96c3e1c4d8212ccf3
|
|
BLAKE2b-256 checksum How to use checksums |
caf93781f0954636459ae2e4ecb27dd4a58c93aa5e1b4d4a14cfe60b819cf8a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 9, 2026.
Transparency log