Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xzkostyan/clickhouse-sqlalchemy
ClickHouse dialect for SQLAlchemy
https://github.com/xzkostyan/clickhouse-sqlalchemy
clickhouse database dialect sqlalchemy yandex
Last synced: 30 days ago
JSON representation
ClickHouse dialect for SQLAlchemy
- Host: GitHub
- URL: https://github.com/xzkostyan/clickhouse-sqlalchemy
- Owner: xzkostyan
- License: other
- Created: 2017-03-29T23:45:58.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-05-16T08:29:04.000Z (7 months ago)
- Last Synced: 2024-05-17T09:01:57.054Z (7 months ago)
- Topics: clickhouse, database, dialect, sqlalchemy, yandex
- Language: Python
- Homepage: https://clickhouse-sqlalchemy.readthedocs.io
- Size: 566 KB
- Stars: 398
- Watchers: 15
- Forks: 116
- Open Issues: 72
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.rst
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-clickhouse - xzkostyan/clickhouse-sqlalchemy - ClickHouse dialect for SQLAlchemy. (Language bindings / Python)
README
ClickHouse SQLAlchemy
=====================ClickHouse dialect for SQLAlchemy to `ClickHouse database `_.
.. image:: https://img.shields.io/pypi/v/clickhouse-sqlalchemy.svg
:target: https://pypi.org/project/clickhouse-sqlalchemy.. image:: https://coveralls.io/repos/github/xzkostyan/clickhouse-sqlalchemy/badge.svg?branch=master
:target: https://coveralls.io/github/xzkostyan/clickhouse-sqlalchemy?branch=master.. image:: https://img.shields.io/pypi/l/clickhouse-sqlalchemy.svg
:target: https://pypi.org/project/clickhouse-sqlalchemy.. image:: https://img.shields.io/pypi/pyversions/clickhouse-sqlalchemy.svg
:target: https://pypi.org/project/clickhouse-sqlalchemy.. image:: https://img.shields.io/pypi/dm/clickhouse-sqlalchemy.svg
:target: https://pypi.org/project/clickhouse-sqlalchemy.. image:: https://github.com/xzkostyan/clickhouse-sqlalchemy/actions/workflows/actions.yml/badge.svg
:target: https://github.com/xzkostyan/clickhouse-sqlalchemy/actions/workflows/actions.ymlDocumentation
=============Documentation is available at https://clickhouse-sqlalchemy.readthedocs.io.
Usage
=====Supported interfaces:
- **native** [recommended] (TCP) via `clickhouse-driver `
- **async native** (TCP) via `asynch `
- **http** via requestsDefine table
.. code-block:: python
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
.. code-block:: python
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
.. code-block:: python
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
`_.