Skip to main content

Simple ClickHouse SQLAlchemy Dialect

Project description

ClickHouse SQLAlchemy

ClickHouse dialect for SQLAlchemy to ClickHouse database.


Documentation is available at


Supported interfaces:

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__ = (


Insert some data

from datetime import date, timedelta

from sqlalchemy import func

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( \
    .filter( > today - timedelta(20)) \


ClickHouse SQLAlchemy is distributed under the MIT license.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clickhouse-sqlalchemy-0.2.1.tar.gz (34.8 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page