> ## 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.

# Python connector reference

> Connection parameters and the cursor API of the e6data Python connector.

For a step-by-step guide, see [Query e6data from Python](/query/connect/python). Source code and full examples live in the [connector repository](https://github.com/e6x-labs/e6data-python-connector).

## Install

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

## Connection parameters

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

conn = Connection(
    host="<host>",
    port=443,
    username="<email>",
    password="<access token>",
    database="<schema>",
    cluster_name="<cluster_name>",
    secure=True,
)
```

| Parameter | Type | Required | Default | Description |
| - | - | - | - | - |
| `host` | str | Yes | | Hostname of the e6data cluster endpoint. |
| `port` | int | Yes | | Port of the endpoint. Use the port shown under **Cluster → Connectivity**. |
| `username` | str | Conditional | `None` | Your e6data email. Required unless you authenticate with OAuth. |
| `password` | str | Conditional | `None` | A [personal access token](/platform/tokens/pat-and-service-account-keys). Required unless you authenticate with OAuth. |
| `database` | str | No | `None` | The schema (database) to query. |
| `catalog` | str | No | `None` | The catalog name. |
| `cluster_name` | str | No | `None` | The cluster to run queries on. |
| `secure` | bool | No | `False` | Set `True` to use TLS. |
| `ssl_cert` | str or bytes | No | `None` | Path to a CA certificate (PEM), or the certificate bytes. |
| `auto_resume` | bool | No | `True` | Resume the cluster automatically if it's suspended. |
| `grpc_options` | dict | No | `None` | Extra gRPC options. |
| `debug` | bool | No | `False` | Turn on debug logging. |
| `require_fastbinary` | bool | No | `True` | Set `False` to use the pure-Python deserializer when the native build dependencies can't be installed. |
| `client_id`, `client_secret`, `token_url` | str | No | `None` | OAuth 2.0 client-credentials settings. Use instead of `username` and `password`. |
| `oauth_scope` | str | No | `None` | Space-separated scopes to request. |
| `access_token` | str | No | `None` | A token you minted yourself. The connector doesn't refresh it. |
| `client_auth_method` | str | No | `"basic"` | How client credentials reach the token endpoint: `"basic"` or `"post"`. |

<Warning>
  Supply exactly one authentication method. Passing both `username`/`password` and OAuth settings raises a `ValueError`.
</Warning>

### Authenticate with OAuth 2.0

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
conn = Connection(
    host="<host>",
    port=443,
    database="<schema>",
    cluster_name="<cluster_name>",
    secure=True,
    client_id="<client_id>",
    client_secret="<client_secret>",
    token_url="https://<your-workspace>/oauth2/token",
)
```

The connector gets a token with the client-credentials grant, caches it, and refreshes it shortly before it expires. OAuth doesn't turn on TLS for you, so set `secure=True`.

## Cursor API

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
cursor = conn.cursor(catalog_name="<catalog>")
query_id = cursor.execute("SELECT * FROM <table>")
rows = cursor.fetchall()
```

| Method | What it does |
| - | - |
| `conn.cursor(catalog_name=...)` | Opens a cursor scoped to a catalog. |
| `cursor.execute(query)` | Runs a statement and returns its query ID. |
| `cursor.fetchall()` | Returns all rows. |
| `cursor.fetchone()` | Returns one row. |
| `cursor.fetchmany(n)` | Returns up to `n` rows. |
| `cursor.fetchall_buffer()` | Returns a generator that streams rows, to keep memory low on large results. |
| `cursor.explain_analyse()` | Returns the execution plan and statistics after a query runs. |
| `cursor.cancel(query_id)` | Aborts a running query. |
| `cursor.clear()` | Frees cached results. Not needed after aborting a query. |
| `cursor.close()` | Closes the cursor. |
| `conn.get_schema_names()` | Lists databases (schemas). |
| `conn.get_tables(database=...)` | Lists tables in a database. |
| `conn.close()` | Closes the connection. |

## See also

* [Query e6data from Python](/query/connect/python)
* [Connecting to the engine](/query/connect)
* [REST API for SQL queries](/query/connect/rest-api-for-sql), a driverless alternative


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