Simple ClickHouse SQLAlchemy Dialect
Project description
ClickHouse SQLAlchemy
ClickHouse dialect for SQLAlchemy to ClickHouse database.
Documentation
Documentation is available at https://clickhouse-sqlalchemy.readthedocs.io.
Usage
Supported interfaces:
native [recommended] (TCP) via clickhouse-driver
http via requests
Define table
from sqlalchemy import create_engine, Column, MetaData from clickhouse_sqlalchemy import ( Table, make_session, get_declarative_base, types, engines ) uri = 'clickhouse+native://localhost/default' engine = create_engine(uri) session = make_session(engine) metadata = MetaData(bind=engine) Base = get_declarative_base(metadata=metadata) class Rate(Base): day = Column(types.Date, primary_key=True) value = Column(types.Int32) __table_args__ = ( engines.Memory(), ) Rate.__table__.create()
Insert some data
from datetime import date, timedelta from sqlalchemy import func today = date.today() rates = [ {'day': today - timedelta(i), 'value': 200 - i} for i in range(100) ]
And query inserted data
session.execute(Rate.__table__.insert(), rates) session.query(func.count(Rate.day)) \ .filter(Rate.day > today - timedelta(20)) \ .scalar()
License
ClickHouse SQLAlchemy is distributed under the MIT license.
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
Close
Hashes for clickhouse-sqlalchemy-0.1.10.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ced3fc148da224aa9bb77a12a492739ecee7414196e8d21826b0fac665d37259 |
|
MD5 | 037ff6d8f133440f88726afbc06eef86 |
|
BLAKE2b-256 | cc08d05e67cc0c1dff04e7ec76d9c22fe569e325ecbb0eea87ac1d46e73e1b1d |