一覧へ戻る
mymarilyn/clickhouse-driver(新しいタブで開きます)
主要言語: Python
ClickHouse Python Driver with native interface support
- star 数
- 1,307
- watcher 数
- 28
- fork 数
- 247
- issue 数
- 79
- 最終更新
- 2026/07/22
主要言語: Python
ClickHouse Python Driver with native interface support
ClickHouse Python Driver with native (TCP) interface support.
Asynchronous wrapper is available here: https://github.com/mymarilyn/aioch
Documentation is available at https://clickhouse-driver.readthedocs.io.
There are two ways to communicate with server:
Pure Client example:
>>> from clickhouse_driver import Client >>> >>> client = Client('localhost') >>> >>> client.execute('SHOW TABLES') [('test',)] >>> client.execute('DROP TABLE IF EXISTS test') [] >>> client.execute('CREATE TABLE test (x Int32) ENGINE = Memory') [] >>> client.execute( ... 'INSERT INTO test (x) VALUES', ... [{'x': 100}] ... ) 1 >>> client.execute('INSERT INTO test (x) VALUES', [[200]]) 1 >>> client.execute( ... 'INSERT INTO test (x) ' ... 'SELECT * FROM system.numbers LIMIT %(limit)s', ... {'limit': 3} ... ) [] >>> client.execute('SELECT sum(x) FROM test') [(303,)]
DB API example:
>>> from clickhouse_driver import connect >>> >>> conn = connect('clickhouse://localhost') >>> cursor = conn.cursor() >>> >>> cursor.execute('SHOW TABLES') >>> cursor.fetchall() [('test',)] >>> cursor.execute('DROP TABLE IF EXISTS test') >>> cursor.fetchall() [] >>> cursor.execute('CREATE TABLE test (x Int32) ENGINE = Memory') >>> cursor.fetchall() [] >>> cursor.executemany( ... 'INSERT INTO test (x) VALUES', ... [{'x': 100}] ... ) >>> cursor.rowcount 1 >>> cursor.executemany('INSERT INTO test (x) VALUES', [[200]]) >>> cursor.rowcount 1 >>> cursor.execute( ... 'INSERT INTO test (x) ' ... 'SELECT * FROM system.numbers LIMIT %(limit)s', ... {'limit': 3} ... ) >>> cursor.rowcount 0 >>> cursor.execute('SELECT sum(x) FROM test') >>> cursor.fetchall() [(303,)]