Python driver with native interface for ClickHouse
Project description
ClickHouse Python Driver
ClickHouse Python Driver with native (TCP) interface support.
Features
Installation
The package can be installed using pip:
pip install clickhouse-driver
You can install extras packages if you need compression support. Example of LZ4 compression requirements installation:
pip install clickhouse-driver[lz4]
You also can specify multiple extras by using comma. Install LZ4 and ZSTD requirements:
pip install clickhouse-driver[lz4,zstd]
Usage example:
from clickhouse_driver.client import Client client = Client('localhost') client.execute('SHOW TABLES') client.execute('DROP TABLE IF EXISTS test') client.execute('CREATE TABLE test (x Int32) ENGINE = Memory') client.execute( 'INSERT INTO test (x) VALUES', [{'x': 1}, {'x': 2}, {'x': 3}, {'x': 100}] ) client.execute('INSERT INTO test (x) VALUES', [[200]]) print(client.execute('SELECT sum(x) FROM test'))
Get client with compression:
from clickhouse_driver.client import Client client_with_lz4 = Client('localhost', compression=True) client_with_lz4 = Client('localhost', compression='lz4') client_with_zstd = Client('localhost', compression='zstd')
CityHash algorithm notes
Unfortunately ClickHouse server comes with built-in old version of CityHash hashing algorithm. That’s why we can’t use original CityHash package. Downgraded version of this algorithm is placed at PyPy.
Connection Parameters
The first parameter host is required. There are some optional parameters:
port is port ClickHouse server is bound to. Default is 9000.
database is database connect to. Default is 'default'.
user. Default is 'default'.
password. Default is '' (no password).
client_name. This name will appear in server logs. Default is 'pyclient'.
compression. Whether or not use compression. Default is False.Possible choices:
True is equivalent to 'lz4'.
'quicklz'.
'lz4'.
'lz4hc' high-compression variant of 'lz4'.
'zstd'.
You can also specify timeouts via:
connect_timeout. Default is 10 seconds.
send_receive_timeout. Default is 300 seconds.
sync_request_timeout. Default is 5 seconds.
License
ClickHouse Python Driver 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.