A Python client working example for connecting to ClickHouse Cloud Service
Learn how to connect to ClickHouse Cloud Service using Python with a step-by-step example using the clickhouse-connect driver.
This is a step by step example on how to start using Python with ClickHouse Cloud service.
Note
Keep in mind that Python versions and libraries dependencies are constantly evolving. Make also sure to use the latest supported versions of both the driver and Python environment when trying this.
At the time of writing this article, we're using the clickhouse-connect driver version 0.5.23
and python 3.11.2
respectively.
Steps
- Check the Python version:
- We'll assemble the project in a folder called
ch-python
:
- Create a dependencies file named
requirements.txt
with:
- Create a python source file named
main.py
:
- Create the virtual environment:
- Load the virtual environment:
Once loaded, your terminal prompt should be prefixed with (venv), install dependencies:
- Launch the code!
Tip
If using an older Python version (e.g. 3.9.6
) you might be getting an ImportError
related to urllib3
library.
In that case either upgrade your Python environment to a newer version or pin the urllib3
version to 1.26.15
in your requirements.txt file.
· 2 min read