Shared ClickHouse connectivity library for Analytic AI services.
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file clickhouse_core-0.2.4.tar.gz.
File metadata
- Download URL: clickhouse_core-0.2.4.tar.gz
- Upload date:
- Size: 17.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78ec6a022afd144f0d3696260b4d4819ab09e213d55357bf97c49b250b79a062
|
|
| MD5 |
7b03d93523cd202f6097250eca2f157d
|
|
| BLAKE2b-256 |
c14bf5493887c4bd3ac3a1872cf2613df2eaea2098bebf1ec085dfc1689f484a
|
Provenance
The following attestation bundles were made for clickhouse_core-0.2.4.tar.gz:
Publisher:
publish.yml on sreeyenan/clickhouse_core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clickhouse_core-0.2.4.tar.gz -
Subject digest:
78ec6a022afd144f0d3696260b4d4819ab09e213d55357bf97c49b250b79a062 - Sigstore transparency entry: 1573453496
- Sigstore integration time:
-
Permalink:
sreeyenan/clickhouse_core@a7bb08206ce019b2d283dd3ff36129298064a0a2 -
Branch / Tag:
refs/tags/v0.2.4 - Owner: https://github.com/sreeyenan
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a7bb08206ce019b2d283dd3ff36129298064a0a2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file clickhouse_core-0.2.4-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: clickhouse_core-0.2.4-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 232.4 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74fc1897f43bda88fe330a7ccc23b5c15f034c95b0c2cac080113e515cf76812
|
|
| MD5 |
20eff50d50644f085a4c8cb6b0769aed
|
|
| BLAKE2b-256 |
51d9d1c913861d4bcb6f0f19f900214451a87de9a5e07cdb04b145542e9d713b
|
Provenance
The following attestation bundles were made for clickhouse_core-0.2.4-cp311-cp311-win_amd64.whl:
Publisher:
publish.yml on sreeyenan/clickhouse_core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clickhouse_core-0.2.4-cp311-cp311-win_amd64.whl -
Subject digest:
74fc1897f43bda88fe330a7ccc23b5c15f034c95b0c2cac080113e515cf76812 - Sigstore transparency entry: 1573453501
- Sigstore integration time:
-
Permalink:
sreeyenan/clickhouse_core@a7bb08206ce019b2d283dd3ff36129298064a0a2 -
Branch / Tag:
refs/tags/v0.2.4 - Owner: https://github.com/sreeyenan
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a7bb08206ce019b2d283dd3ff36129298064a0a2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file clickhouse_core-0.2.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: clickhouse_core-0.2.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ff563723a1b1406125ae9d0f4aa2877791d33316651ba45899bf6fde1093e90
|
|
| MD5 |
7d49cf990b2428a4aa27f31c3c9e1881
|
|
| BLAKE2b-256 |
9ac780a29219013a99caf3f638251ba969e11cb58edbc0ec92b7484ece794660
|
Provenance
The following attestation bundles were made for clickhouse_core-0.2.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish.yml on sreeyenan/clickhouse_core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clickhouse_core-0.2.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
2ff563723a1b1406125ae9d0f4aa2877791d33316651ba45899bf6fde1093e90 - Sigstore transparency entry: 1573453520
- Sigstore integration time:
-
Permalink:
sreeyenan/clickhouse_core@a7bb08206ce019b2d283dd3ff36129298064a0a2 -
Branch / Tag:
refs/tags/v0.2.4 - Owner: https://github.com/sreeyenan
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a7bb08206ce019b2d283dd3ff36129298064a0a2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file clickhouse_core-0.2.4-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.
File metadata
- Download URL: clickhouse_core-0.2.4-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ i686, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0373d3ceac24e4cf6bfd50aeaaeca4cef476f045fd61ea8346156bedd605e8ff
|
|
| MD5 |
1781c16807ac33f010142146d939dd8c
|
|
| BLAKE2b-256 |
8381f47a818107ab0ede5abe4dee8906bc41c3a05a1f070f8bbcc54e9a3601e4
|
Provenance
The following attestation bundles were made for clickhouse_core-0.2.4-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl:
Publisher:
publish.yml on sreeyenan/clickhouse_core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clickhouse_core-0.2.4-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl -
Subject digest:
0373d3ceac24e4cf6bfd50aeaaeca4cef476f045fd61ea8346156bedd605e8ff - Sigstore transparency entry: 1573453512
- Sigstore integration time:
-
Permalink:
sreeyenan/clickhouse_core@a7bb08206ce019b2d283dd3ff36129298064a0a2 -
Branch / Tag:
refs/tags/v0.2.4 - Owner: https://github.com/sreeyenan
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a7bb08206ce019b2d283dd3ff36129298064a0a2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file clickhouse_core-0.2.4-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: clickhouse_core-0.2.4-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 253.7 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b9047152507bad99254bfde4585d1020d4d445144132cc155fba7ce3b39e320
|
|
| MD5 |
31b5bf7faf83b00db082dd8355c88ab2
|
|
| BLAKE2b-256 |
3cee3a3fed954fe86187f097e1fe67f0a3a9034ebbe21d4c26774de5be39a6ff
|
Provenance
The following attestation bundles were made for clickhouse_core-0.2.4-cp311-cp311-macosx_11_0_arm64.whl:
Publisher:
publish.yml on sreeyenan/clickhouse_core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clickhouse_core-0.2.4-cp311-cp311-macosx_11_0_arm64.whl -
Subject digest:
9b9047152507bad99254bfde4585d1020d4d445144132cc155fba7ce3b39e320 - Sigstore transparency entry: 1573453506
- Sigstore integration time:
-
Permalink:
sreeyenan/clickhouse_core@a7bb08206ce019b2d283dd3ff36129298064a0a2 -
Branch / Tag:
refs/tags/v0.2.4 - Owner: https://github.com/sreeyenan
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a7bb08206ce019b2d283dd3ff36129298064a0a2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file clickhouse_core-0.2.4-cp311-cp311-macosx_10_9_x86_64.whl.
File metadata
- Download URL: clickhouse_core-0.2.4-cp311-cp311-macosx_10_9_x86_64.whl
- Upload date:
- Size: 256.0 kB
- Tags: CPython 3.11, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
afbe97e66f6a1ed2f820d4a7a39692c558d15b08933326e60b57e622194cea39
|
|
| MD5 |
c977436500caf8dbb5ab5cab5f560bfd
|
|
| BLAKE2b-256 |
96341182e8ad955d5bf78af0cc8405ebf5516f543625b0234cb75689b2ed4b24
|
Provenance
The following attestation bundles were made for clickhouse_core-0.2.4-cp311-cp311-macosx_10_9_x86_64.whl:
Publisher:
publish.yml on sreeyenan/clickhouse_core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clickhouse_core-0.2.4-cp311-cp311-macosx_10_9_x86_64.whl -
Subject digest:
afbe97e66f6a1ed2f820d4a7a39692c558d15b08933326e60b57e622194cea39 - Sigstore transparency entry: 1573453524
- Sigstore integration time:
-
Permalink:
sreeyenan/clickhouse_core@a7bb08206ce019b2d283dd3ff36129298064a0a2 -
Branch / Tag:
refs/tags/v0.2.4 - Owner: https://github.com/sreeyenan
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a7bb08206ce019b2d283dd3ff36129298064a0a2 -
Trigger Event:
push
-
Statement type: