> ## Documentation Index
> Fetch the complete documentation index at: https://docs.e6data.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Query e6data from Python

> Install the Python connector, connect to a cluster, and run SQL from your own code.

How-to guide
All deployments
Owner: Query team

When you finish

Your script connects to a cluster, runs a query, and prints the rows.

## Before you start

You need:

* A running Query Engine cluster. On CloudPrem, the cluster also needs ingress. See [Configure cluster ingress](/query/clusters/ingress.md).
* A personal access token. See [Create, rotate and revoke tokens](/platform/tokens/create-rotate-revoke.md).
* Python 3, with a C++ compiler. On Windows, install Visual C++ Build Tools first (see [Windows setup](#windows-setup) below).

Find the host, port and cluster name in the console under **Cluster → Connectivity**.

**1. Install the connector**

Install the package from PyPI.

```bash terminal theme={"theme":{"light":"github-light","dark":"github-dark"}}
pip install --no-cache-dir e6data-python-connector
```

On Amazon Linux, CentOS, Ubuntu or Debian, install the build dependencies first if the install fails:

```bash Amazon Linux / CentOS theme={"theme":{"light":"github-light","dark":"github-dark"}}
yum install python3-devel gcc-c++ -y
pip install wheel
```

```bash Ubuntu / Debian theme={"theme":{"light":"github-light","dark":"github-dark"}}
apt install python3-dev g++ -y
pip install wheel
```

**2. Set your credentials**

Set the cluster host, your e6data email and your access token as environment variables. Do not hardcode them in your script.

```bash terminal theme={"theme":{"light":"github-light","dark":"github-dark"}}
export E6_HOST="<cluster host>"
export E6_USER="you@company.com"
export E6_TOKEN="<access token>"
```

**3. Connect and run a query**

Open a connection to the cluster, create a cursor on your catalog, and run SQL.

```python query.py theme={"theme":{"light":"github-light","dark":"github-dark"}}
import os
from e6data_python_connector import Connection

conn = Connection(
    host=os.getenv("E6_HOST"),
    port=443,                         # use the port shown under Cluster → Connectivity
    username=os.getenv("E6_USER"),    # your e6data email
    password=os.getenv("E6_TOKEN"),   # a personal access token
    database="<schema>",
    cluster_name="<cluster_name>",
    secure=True,                      # use TLS
)

cursor = conn.cursor(catalog_name="<catalog>")
query_id = cursor.execute("SELECT * FROM <table> LIMIT 10")
for row in cursor.fetchall():
    print(row)
```

> [!TIP]
>
> **Large results.** Use `cursor.fetchmany(500)` to limit rows, or loop over `cursor.fetchall_buffer()` to stream rows without loading them all into memory.

**4. Close the connection**

Clear and close the cursor, then close the connection. This frees old results from memory.

```python query.py theme={"theme":{"light":"github-light","dark":"github-dark"}}
cursor.clear()   # not needed if you aborted the query
cursor.close()
conn.close()
```

## Windows setup

The connector uses a C-based deserialization library (`fastbinary`). On Windows it works only when Visual C++ Build Tools are installed. Without them you see this error:

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
ImportError: cannot import name 'fastbinary' from 'thrift.protocol'
```

To fix it:

1. Install [Visual C++ Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/) and select the **Desktop Development with C++** workload. Launch the Build Tools once after installing.
2. Create and activate a virtual environment:
   ```bat theme={"theme":{"light":"github-light","dark":"github-dark"}}
   python -m venv <env_name>
   <env_name>\Scripts\activate.bat
   ```
3. Install the connector in that environment:
   ```bat theme={"theme":{"light":"github-light","dark":"github-dark"}}
   pip install --no-cache-dir e6data-python-connector
   ```

If you can't install the build tools, pass `require_fastbinary=False` to `Connection`. The connector then uses a pure-Python deserializer, which is about 2 to 3 times slower but otherwise works the same.

## Related

> **[Python connector reference](/query/connectivity-reference/python-connector.md)**
>
> Reference · Connection parameters and the cursor API.

> **[REST API for SQL queries](/query/connect/rest-api-for-sql.md)**
>
> How-to · A driverless alternative over HTTPS.

> **[Personal access tokens](/platform/tokens/pat-and-service-account-keys.md)**
>
> Platform · Tokens the connector signs in with.

Source code: [e6data-python-connector on GitHub](https://github.com/e6x-labs/e6data-python-connector) · Package: [PyPI](https://pypi.org/project/e6data-python-connector/)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.