You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: 'Options for connecting to ClickHouse from Python'
5
5
slug: /integrations/python
6
6
description: 'The ClickHouse Connect project suite for connecting Python to ClickHouse'
7
7
title: 'Python Integration with ClickHouse Connect'
8
8
doc_type: 'guide'
9
9
---
10
10
11
-
import ConnectionDetails from '@site/docs/_snippets/_gather_your_details_http.mdx';
11
+
import Tabs from '@theme/Tabs';
12
+
import TabItem from '@theme/TabItem';
13
+
import CodeBlock from '@theme/CodeBlock';
12
14
13
-
# Python Integration with ClickHouse Connect
15
+
import ConnectionDetails from '@site/docs/_snippets/_gather_your_details_http.mdx';
14
16
15
-
##Introduction {#introduction}
17
+
# Introduction {#introduction}
16
18
17
19
ClickHouse Connect is a core database driver providing interoperability with a wide range of Python applications.
18
20
19
21
- The main interface is the `Client` object in the package `clickhouse_connect.driver`. That core package also includes assorted helper classes and utility functions used for communicating with the ClickHouse server and "context" implementations for advanced management of insert and select queries.
20
22
- The `clickhouse_connect.datatypes` package provides a base implementation and subclasses for all non-experimental ClickHouse datatypes. Its primary functionality is serialization and deserialization of ClickHouse data into the ClickHouse "Native" binary columnar format, used to achieve the most efficient transport between ClickHouse and client applications.
21
23
- The Cython/C classes in the `clickhouse_connect.cdriver` package optimize some of the most common serializations and deserializations for significantly improved performance over pure Python.
22
24
- There is a [SQLAlchemy](https://www.sqlalchemy.org/) dialect in the package `clickhouse_connect.cc_sqlalchemy` which is built off of the `datatypes` and `dbi` packages. This implementation supports SQLAlchemy Core functionality including `SELECT` queries with `JOIN`s (`INNER`, `LEFT OUTER`, `FULL OUTER`, `CROSS`), `WHERE` clauses, `ORDER BY`, `LIMIT`/`OFFSET`, `DISTINCT` operations, lightweight `DELETE` statements with `WHERE` conditions, table reflection, and basic DDL operations (`CREATE TABLE`, `CREATE`/`DROP DATABASE`). While it does not support advanced ORM features or advanced DDL features, it provides robust query capabilities suitable for most analytical workloads against ClickHouse's OLAP-oriented database.
23
-
- The core driver and ClickHouse Connect SQLAlchemy implementation are the preferred method for connecting ClickHouse to Apache Superset. Use the `ClickHouse Connect` database connection, or `clickhousedb` SQLAlchemy dialect connection string.
25
+
- The core driver and [ClickHouse Connect SQLAlchemy](sqlalchemy.md) implementation are the preferred method for connecting ClickHouse to Apache Superset. Use the `ClickHouse Connect` database connection, or `clickhousedb` SQLAlchemy dialect connection string.
24
26
25
27
26
-
This documentation is current as of the beta release 0.9.3.
28
+
This documentation is current as of the clickhouse-connect beta release 0.9.2.
27
29
28
30
:::note
29
31
The official ClickHouse Connect Python driver uses the HTTP protocol for communication with the ClickHouse server. It has some advantages (such as better flexibility, HTTP load balancer support, and improved compatibility with JDBC-based tools) and disadvantages (such as slightly lower compression and performance, and a lack of support for some complex features of the native TCP-based protocol). For some use cases, you may consider using one of the [Community Python drivers](/interfaces/third-party/client-libraries.md) that use the native TCP-based protocol.
30
32
:::
31
33
32
-
###Requirements and compatibility {#requirements-and-compatibility}
34
+
## Requirements and compatibility {#requirements-and-compatibility}
@@ -44,13 +46,13 @@ The official ClickHouse Connect Python driver uses the HTTP protocol for communi
44
46
45
47
¹ClickHouse Connect has been explicitly tested against the listed platforms. In addition, untested binary wheels (with C optimization) are built for all architectures supported by the excellent [`cibuildwheel`](https://cibuildwheel.readthedocs.io/en/stable/) project. Finally, because ClickHouse Connect can also run as pure Python, the source installation should work on any recent Python installation.
46
48
47
-
²SQLAlchemy support is limited to Core functionality (queries, basic DDL). ORM features are not supported.
49
+
²SQLAlchemy support is limited to Core functionality (queries, basic DDL). ORM features are not supported. See [SQLAlchemy Integration Support](sqlalchemy.md) docs for details.
48
50
49
51
³ClickHouse Connect generally works well with versions outside the officially supported range.
50
52
51
-
###Installation {#installation}
53
+
## Installation {#installation}
52
54
53
-
Install ClickHouse Connect from PyPI via pip:
55
+
Install ClickHouse Connect from [PyPI](https://pypi.org/project/clickhouse-connect/) via pip:
54
56
55
57
`pip install clickhouse-connect`
56
58
@@ -59,17 +61,17 @@ ClickHouse Connect can also be installed from source:
59
61
* (Optional) run `pip install cython` to build and enable the C/Cython optimizations
60
62
*`cd` to the project root directory and run `pip install .`
61
63
62
-
###Support policy {#support-policy}
64
+
## Support policy {#support-policy}
63
65
64
66
ClickHouse Connect is currently in beta and only the current beta release is actively supported. Please update to the latest version before reporting any issues. Issues should be filed in the [GitHub project](https://github.com/ClickHouse/clickhouse-connect/issues). Future releases of ClickHouse Connect are guaranteed to be compatible with actively supported ClickHouse versions at the time of release. ClickHouse Connect officially supports the current stable release and the two most recent LTS releases of ClickHouse server, matching ClickHouse's own [support policy](https://clickhouse.com/docs/knowledgebase/production#how-to-choose-between-clickhouse-releases). Our CI test matrix validates against the latest two LTS releases and the last three stable versions. Due to the HTTP protocol and minimal breaking changes between ClickHouse releases, ClickHouse Connect generally works well with versions outside the officially supported range, though compatibility with certain advanced data types may vary.
65
67
66
-
###Basic usage {#basic-usage}
68
+
## Basic usage {#basic-usage}
67
69
68
70
### Gather your connection details {#gather-your-connection-details}
69
71
70
72
<ConnectionDetails />
71
73
72
-
####Establish a connection {#establish-a-connection}
74
+
### Establish a connection {#establish-a-connection}
73
75
74
76
There are two examples shown for connecting to ClickHouse:
#####Use a ClickHouse Connect client instance to connect to a ClickHouse Cloud service: {#use-a-clickhouse-connect-client-instance-to-connect-to-a-clickhouse-cloud-service}
88
+
#### Use a ClickHouse Connect client instance to connect to a ClickHouse Cloud service: {#use-a-clickhouse-connect-client-instance-to-connect-to-a-clickhouse-cloud-service}
87
89
88
90
:::tip
89
91
Use the connection details gathered earlier. ClickHouse Cloud services require TLS, so use port 8443.
0 commit comments