databricks-sql-connector

Databricks SQL Connector for Python

Apache-2.0 101 个版本 Python <4.0.0,>=3.8.0
Databricks <databricks-sql-connector-maintainers@databricks.com>
安装
pip install databricks-sql-connector
poetry add databricks-sql-connector
pipenv install databricks-sql-connector
conda install databricks-sql-connector
描述

Databricks SQL Connector for Python

PyPI Downloads

The Databricks SQL Connector for Python allows you to develop Python applications that connect to Databricks clusters and SQL warehouses. It is a Thrift-based client with no dependencies on ODBC or JDBC. It conforms to the Python DB API 2.0 specification.

This connector uses Arrow as the data-exchange format, and supports APIs (e.g. fetchmany_arrow) to directly fetch Arrow tables. Arrow tables are wrapped in the ArrowQueue class to provide a natural API to get several rows at a time. PyArrow is required to enable this and use these APIs, you can install it via pip install pyarrow or pip install databricks-sql-connector[pyarrow].

The connector includes built-in support for HTTP/HTTPS proxy servers with multiple authentication methods including basic authentication and Kerberos/Negotiate authentication. See docs/proxy.md and examples/proxy_authentication.py for details.

You are welcome to file an issue here for general use cases. You can also contact Databricks Support here.

Requirements

Python 3.9 or above is required.

Documentation

For the latest documentation, see

Quickstart

Installing the core library

Install using pip install databricks-sql-connector

Installing the core library with PyArrow

Install using pip install databricks-sql-connector[pyarrow]

Installing with the Rust kernel backend (use_kernel=True)

Install using pip install databricks-sql-connector[kernel]

This adds the optional databricks-sql-kernel extension (a native Rust client core, exposed via PyO3). Pass use_kernel=True to sql.connect(...) to route the connection through it instead of the default Thrift backend:

connection = sql.connect(
  server_hostname=host,
  http_path=http_path,
  access_token=token,
  use_kernel=True,
)

Notes:

  • Requires Python >= 3.10 (the kernel wheel is published as cp310-abi3). On older interpreters the [kernel] extra installs nothing and use_kernel=True raises an ImportError.
  • The extra also pulls in PyArrow, which the kernel result path requires.
  • Authentication supports PAT (access_token), OAuth M2M, and OAuth U2M.
export DATABRICKS_HOST=********.databricks.com
export DATABRICKS_HTTP_PATH=/sql/1.0/endpoints/****************

Example usage:

import os
from databricks import sql

host = os.getenv("DATABRICKS_HOST")
http_path = os.getenv("DATABRICKS_HTTP_PATH")

connection = sql.connect(
  server_hostname=host,
  http_path=http_path)

cursor = connection.cursor()
cursor.execute('SELECT :param `p`, * FROM RANGE(10)', {"param": "foo"})
result = cursor.fetchall()
for row in result:
  print(row)

cursor.close()
connection.close()

In the above example:

  • server-hostname is the Databricks instance host name.
  • http-path is the HTTP Path either to a Databricks SQL endpoint (e.g. /sql/1.0/endpoints/1234567890abcdef), or to a Databricks Runtime interactive cluster (e.g. /sql/protocolv1/o/1234567890123456/1234-123456-slid123)

Note: This example uses Databricks OAuth U2M to authenticate the target Databricks user account and needs to open the browser for authentication. So it can only run on the user's machine.

Transaction Support

The connector supports multi-statement transactions with manual commit/rollback control. Set connection.autocommit = False to disable autocommit mode, then use connection.commit() and connection.rollback() to control transactions.

For detailed documentation, examples, and best practices, see TRANSACTIONS.md.

SQLAlchemy

Starting from databricks-sql-connector version 4.0.0 SQLAlchemy support has been extracted to a new library databricks-sqlalchemy.

Quick SQLAlchemy guide

Users can now choose between using the SQLAlchemy v1 or SQLAlchemy v2 dialects with the connector core

  • Install the latest SQLAlchemy v1 using pip install databricks-sqlalchemy~=1.0
  • Install SQLAlchemy v2 using pip install databricks-sqlalchemy

Contributing

See CONTRIBUTING.md

License

Apache License 2.0

版本列表
4.3.0 2026-06-15
4.3.0rc1 2026-06-11
4.2.7 2026-06-04
4.2.6 2026-04-23
4.2.5 2026-02-09
4.2.4 2026-01-08
4.2.3 2025-12-18
4.2.2 2025-12-04
4.2.1 2025-11-20
4.2.0 2025-11-14
4.1.5 2026-03-23
4.1.4 2025-10-15
4.1.3 2025-09-17
4.1.2 2025-08-22
4.1.1 2025-08-21
4.1.0 2025-08-18
4.0.6 2025-08-18
4.0.5 2025-06-26
4.0.4 2025-06-16
4.0.3 2025-04-22
4.0.2 2025-04-01
4.0.1 2025-03-19
4.0.0 2025-01-22
4.0.0b4 2024-11-13
4.0.0b3 2024-11-06
4.0.0b2 2024-11-05
4.0.0b1 2024-10-14
4.0.0b0 2024-10-08
3.7.5 2026-03-02
3.7.4 2025-04-22
3.7.3 2025-02-28
3.7.2 2025-02-03
3.7.1 2025-01-07
3.7.0 2024-12-23
3.6.0 2024-10-25
3.5.0 2024-10-18
3.4.0 2024-08-27
3.3.0 2024-07-17
3.2.0 2024-06-14
3.1.2 2024-04-18
3.1.1 2024-03-19
3.1.0 2024-02-17
3.0.3 2024-02-02
3.0.2 2024-01-26
3.0.1 2023-12-01
3.0.0 2023-11-17
3.0.3b1 2024-01-29
3.0.0b1 2023-11-01
2.9.6 2024-04-18
2.9.5 2024-03-19
2.9.4 2024-02-21
2.9.3 2023-08-24
2.9.2 2023-08-18
2.9.2.dev1 2023-08-15
2.9.1 2023-08-11
2.9.1.dev1 2023-08-11
2.9.0 2023-08-10
2.9.4b1 2024-02-16
2.8.0 2023-07-21
2.7.1.dev3 2023-07-12
2.7.1.dev2 2023-07-12
2.7.1.dev1 2023-07-10
2.7.0 2023-06-26
2.6.3.dev1 2023-06-21
2.6.2 2023-06-14
2.6.1 2023-06-08
2.6.1.dev1 2023-06-08
2.6.0 2023-06-07
2.5.2 2023-05-09
2.5.1 2023-04-28
2.5.0 2023-04-15
2.4.1 2023-03-21
2.4.0 2023-02-21
2.3.1.dev1 2023-01-12
2.3.0 2023-01-10
2.2.2 2023-01-03
2.2.1 2022-11-28
2.2.0 2022-11-17
2.2.dev1676479629 2023-02-15
2.2.dev1675985183 2023-02-09
2.2.dev1669954165 2022-12-02
2.1.0 2022-10-01
2.1.dev1672379067 2022-12-30
2.1.dev1666624638 2022-10-26
2.0.5 2022-08-23
2.0.4 2022-08-17
2.0.3 2022-08-10
2.0.2 2022-05-05
2.0.1 2022-04-22
2.0.0 2022-04-20
2.0.0b2 2022-04-11
2.0.0b1 2022-03-07
2.0.0b0 2022-02-24
1.0.2 2022-04-07
1.0.1 2022-02-02
1.0.0 2022-01-25
0.9.4 2022-01-11
0.9.3 2021-12-08
0.9.2 2021-12-02
0.9.1 2021-09-02
0.9.0 2021-08-25