Registry / database / databricks-sql

databricks-sql

JSON →
library1.0.0pypypiunverified

Databricks SQL is a Python framework designed for easy interaction with Databricks SQL Endpoints. It provides a fluent API for building and executing SQL queries, simplifying data operations for Python developers. The library recently reached version 1.0.0, indicating a stable API after rapid initial development.

pip install databricks-sql
INSTALL
IMPORT
SIG · DATABRICKS-SQL
D
databricks-sql
databasepythonv1.0.0
Install
13.3s avg
Import
Disk
323MB
Pass rate
3/ 10
Env Coverage3 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
✓ 12.9s
py 3.11
✕ build_error
✓ 12.35s
py 3.12
✕ build_error
✕ build_error
py 3.13
✕ build_error
✕ build_error
py 3.9
✕ build_error
✓ 14.7s
323MB installed
● package 323MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

DatabricksSQL
from databricks_sql import DatabricksSQL

This quickstart demonstrates how to connect to Databricks SQL using environment variables for authentication and perform a simple SELECT query. Replace `your_schema.users` with an actual table in your Databricks workspace. It highlights the fluent API pattern for query construction.

import os from databricks_sql import DatabricksSQL # Ensure these environment variables are set for authentication # DATABRICKS_SERVER_HOSTNAME (e.g., 'dbc-xxxx.cloud.databricks.com') # DATABRICKS_HTTP_PATH (e.g., '/sql/1.0/endpoints/xxxx') # DATABRICKS_ACCESS_TOKEN (Databricks personal access token) # Initialize the DatabricksSQL client db_sql = DatabricksSQL( server_hostname=os.environ.get("DATABRICKS_SERVER_HOSTNAME", ""), http_path=os.environ.get("DATABRICKS_HTTP_PATH", ""), access_token=os.environ.get("DATABRICKS_ACCESS_TOKEN", "") ) try: # Example: Select data from a table named 'users' # Replace 'your_schema.users' with an actual table in your Databricks workspace result = db_sql.select("id", "name").from_table("your_schema.users").limit(5).fetch_all() print("Fetched data:") for row in result: print(row) # Example: Insert data (if table allows) # db_sql.insert().into_table("your_schema.new_users").columns("id", "name").values(1, "Alice").execute() # print("Data inserted.") except Exception as e: print(f"An error occurred: {e}") print("Please ensure your Databricks connection details (server_hostname, http_path, access_token) are correctly configured.")
Debug
Known issues
breakingThe internal module name was changed in version 0.0.1. While unlikely to affect many users given the library's recency, it means any code written for version 0.0.0 would have broken import paths.
fix
Ensure all imports are `from databricks_sql import ...`.
affects: 0.0.0 to 0.0.1+
gotchaFailing to provide correct Databricks connection parameters (server hostname, HTTP path, access token) will lead to authentication errors from the underlying `databricks-api` library. This is the most common cause of initial connection failures.
fix
Verify that `DATABRICKS_SERVER_HOSTNAME`, `DATABRICKS_HTTP_PATH`, and `DATABRICKS_ACCESS_TOKEN` environment variables are correctly set, or pass the credentials directly as arguments to `DatabricksSQL()`.
affects: All versions
gotchaThe query builder methods (e.g., `select`, `from_table`, `where`) return builder objects. You must call a terminal execution method like `.fetch_all()`, `.fetch_one()`, `.fetch_dataframe()`, or `.execute()` to run the query and retrieve results.
fix
Always append an execution method at the end of your query chain, e.g., `db_sql.select(...).from_table(...).fetch_all()`.
affects: All versions
gotchaThis library relies on `databricks-api`. Specific error messages or behaviors related to connectivity, authentication, or underlying API calls might originate from `databricks-api` itself. Consult its documentation for deeper troubleshooting if `databricks-sql` errors are unclear.
fix
When debugging connection or low-level API issues, consider reviewing the `databricks-api` documentation or source code.
affects: All versions
Upgrade
Version history
1.0.0latest on PyPI · released Dec 18, 2022
Audit
Dependencies
databricks-apirequiredThis library wraps the functionality of databricks-api for underlying communication with Databricks.
Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
databricks-sql — pip install databricks-sql · libregistry