wclickhouse
A high-performance ClickHouse ORM for Python using Pydantic v2 and clickhouse-connect.
Features
- Pydantic v2 Integration: Define your ClickHouse tables as Pydantic models.
- Auto-Sync: Automatically creates tables and syncs schema (adds missing columns).
- Dual API: Full support for both Synchronous and Asynchronous operations.
- Bulk Insert Optimized: Built-in support for efficient bulk insertions, essential for ClickHouse performance.
- Type Safety: Automatic mapping between Python/Pydantic types and ClickHouse analytical types (Arrays, DateTime64, etc.).
- DataFrames: Native support for inserting Pandas DataFrames.
Installation
pip install wclickhouse
Quick Start
from pydantic import BaseModel
from wclickhouse import WClickHouse
from datetime import datetime
from typing import List
# 1. Define your model
class AnalyticsEvent(BaseModel):
event_id: int
event_name: str
properties: List[str]
created_at: datetime = datetime.now()
# 2. Configure connection
db_config = {
"host": "localhost",
"port": 8124,
"username": "default",
"password": "",
"database": "default"
}
# 3. Initialize (Auto-creates table)
db = WClickHouse(AnalyticsEvent, db_config)
# 4. Bulk Insert (Best for ClickHouse)
events = [
AnalyticsEvent(event_id=1, event_name="login", properties=["web", "chrome"]),
AnalyticsEvent(event_id=2, event_name="purchase", properties=["mobile", "ios"])
]
db.insert_many(events)
# 5. Query
results = db.get_all()
print(f"Total events: {len(results)}")
Performance Note
ClickHouse is an OLAP database. For best performance:
- Prefer
insert_many()over multipleinsert()calls. - Large batches (1,000 to 100,000 rows) are recommended.
- Use the
MergeTreeengine (default) for production workloads.
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
wclickhouse-1.0.0.tar.gz
(19.6 kB
view details)
Built Distribution
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 wclickhouse-1.0.0.tar.gz.
File metadata
- Download URL: wclickhouse-1.0.0.tar.gz
- Upload date:
- Size: 19.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
11d7f7842e336d359ac926f4549833151732ae4c329cdbdf3698abce7d111839
|
|
| MD5 |
496e61d62d2820b3552293e7b0a37e89
|
|
| BLAKE2b-256 |
f2c8168eeb67dd61b17247641426bc2996cf2d2a87b40bb03197363b792125bc
|
File details
Details for the file wclickhouse-1.0.0-py3-none-any.whl.
File metadata
- Download URL: wclickhouse-1.0.0-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
66e858b142f5a13b084c7582a4ea79674f05f34ac72188a699a63c1d209b4d8d
|
|
| MD5 |
69a6d595b0855d1d4840956f855325ca
|
|
| BLAKE2b-256 |
92a0ab3c6621b4bfabd207bd2ae80355e6c6db922e648d759ca009e6d635e3ed
|