The Databricks SQL Connector for Python is a Python library that enables running SQL commands on Databricks clusters and SQL warehouses. It is a Thrift-based client, conforms to the Python DB API 2.0 specification, and uses Apache Arrow for efficient data exchange. The library is actively maintained with frequent releases, often multiple times a month.
pip install databricks-sql-connectorVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to establish a connection to a Databricks SQL warehouse using a Personal Access Token (PAT) and execute a simple query. Ensure that `DATABRICKS_SERVER_HOSTNAME`, `DATABRICKS_HTTP_PATH`, and `DATABRICKS_TOKEN` environment variables are set with your Databricks connection details.
Install with `pip install databricks-sql-connector[pyarrow]` or `pip install pyarrow` separately.
Install the separate SQLAlchemy dialect: `pip install databricks-sqlalchemy`.
Optionally, use the `databricks-sqlalchemy` engine for `pandas.read_sql` to suppress the warning or if broader SQLAlchemy compatibility is needed.
Consider using alternative methods for large inserts, or a dedicated fix package like `pandas-tosql-dbx-fix` which compiles the SQL query before sending it.
Ensure `autocommit` is managed correctly by the connector's transaction methods. For explicit control, set `autocommit=False` during connection establishment or directly on the connection object, then use `commit()`/`rollback()`. Avoid direct setting if it's causing the `CONFIG_NOT_AVAILABLE` error.
Ensure your environment uses Python 3.9 or newer when working with `databricks-sql-connector` versions 4.x.x.
Ensure C build tools (e.g., `gcc`, `build-base` for Alpine) are installed in your environment before installing `databricks-sql-connector`.
Ensure `databricks-sql-connector` is installed using `pip install databricks-sql-connector`. The correct import for the SQL connector is `from databricks.sql import connect`.
Double-check that `server_hostname`, `http_path`, and `access_token` are correct and have the necessary permissions. Ensure there are no typos, leading/trailing spaces, or incorrect environment variable configurations. Also, confirm network connectivity to the Databricks workspace.
Verify that all connection parameters are explicitly set and are not `None`. For example, if using environment variables, ensure they are defined in your execution environment: `os.getenv("DATABRICKS_SERVER_HOSTNAME")` must return a string, not `None`.Install the missing `packaging` library: `pip install packaging`.
Pin the `databricks-sql-connector` version to an earlier compatible version (e.g., `pip install databricks-sql-connector==4.0.5`) or update the dependent library (like `dbt-databricks`) to a version that is compatible with your current `databricks-sql-connector` version.