Runs SQL against a Databricks SQL warehouse via the Statement Execution API, streams the Arrow-IPC result chunks with backpressure into DuckDB for JSON/rows/Arrow serialization -- no pyarrow required.
Project description
duckbricks
Runs SQL against a Databricks SQL warehouse via the Statement Execution API, streams the Arrow-IPC result chunks with backpressure into DuckDB (a thin Arrow-to-JSON/rows converter, not a query engine), preserving chunk order with SSE-safe heartbeats during slow cold-starts.
- No pyarrow/pandas/numpy dependency chain -- chunks are parsed via nanoarrow and handed to DuckDB through the Arrow C Data Interface.
- Bring-your-own-auth -- a static token or your own token-refresh callable. No cloud-SDK dependency baked in.
- Result-order preserved even though chunks can complete out of order over the network.
- Heartbeats between slow chunks, so a caller streaming this over e.g. SSE never goes silent.
Install
pip install duckbricks[duckdb]
The duckdb extra pulls in duckdb + nanoarrow, needed for run_query/stream_query_json/etc. Omit it if you only want DatabricksClient.execute_json_statement (plain JSON rows, no Arrow/DuckDB involved).
Quickstart
import asyncio
from duckbricks import DatabricksClient, run_query, stream_query_json
async def main():
client = DatabricksClient(
host="adb-1234567890.1.azuredatabricks.net",
warehouse_id="abcd1234efgh5678",
token="dapi...", # or token_provider=... -- see Auth below
)
result = await run_query(client, "SELECT * FROM my_catalog.my_schema.my_table LIMIT 100")
print(result.dicts())
async for row_json in stream_query_json(client, "SELECT * FROM my_catalog.my_schema.big_table"):
print(row_json) # one ready-to-send JSON string per row
asyncio.run(main())
See examples/basic.py for a runnable version.
Why not databricks-sql-connector?
The official driver is the right choice if you need full DB-API 2.0 compatibility (generic SQL tooling, JDBC/ODBC-style connection semantics). If you just want to pull a query result into your own app as JSON/rows/Arrow, it drags in a lot for that: pandas, thrift, openpyxl, pybreaker, pyjwt, oauthlib, lz4, requests, urllib3 as hard dependencies (pyarrow is at least now optional). duckbricks' core is httpx + tenacity; duckdb/nanoarrow are one opt-in extra, and that's the whole dependency tree.
Auth
DatabricksClient takes either:
token: str-- a static personal access token or pre-issued OAuth token, ortoken_provider-- a callable (sync or async) returning a token string, called on every request.
duckbricks has no opinion on how you get a token and no cloud-SDK dependency of its own. If your provider is expensive to call, cache/refresh inside it -- duckbricks does no caching on your behalf.
client = DatabricksClient(host=..., warehouse_id=..., token_provider=my_token_provider)
For Azure Databricks via Azure AD (azure-identity), see examples/azure_auth.py for a caching token_provider built on DefaultAzureCredential.
API
DatabricksClient(host, warehouse_id, *, token=None, token_provider=None, ...)run_query(client, sql, **kwargs) -> QueryResult-- full result, buffered.run_query_streamed(client, sql, *, as_arrow=False, **kwargs)-- yieldsHEARTBEATwhile waiting, then the finalQueryResultor Arrow bytes.stream_query_json(client, sql, **kwargs)-- yieldsHEARTBEAT, then each row as a JSON string, as soon as its chunk arrives.client.execute_json_statement(sql, ...)-- lower-level: JSON rows straight from Databricks, no duckdb/nanoarrow needed.
run_query/run_query_streamed/stream_query_json all accept catalog, schema, params (Databricks' own [{"name", "value", "type"}] named-parameter format), row_limit, offset, and total_timeout_s.
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file duckbricks-0.1.0.tar.gz.
File metadata
- Download URL: duckbricks-0.1.0.tar.gz
- Upload date:
- Size: 35.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1bafabf16027f2da44b1f343e46aa6686e1624b0d60a60d879bd9d4e4534a0b
|
|
| MD5 |
6315ba50eee6e878458ddd37f6ba191c
|
|
| BLAKE2b-256 |
68b098a519e90da6e5c5e4068eb19bdd7c26a28cae5d634de712fc36b9eb08fe
|
Provenance
The following attestation bundles were made for duckbricks-0.1.0.tar.gz:
Publisher:
release.yml on bmsuisse/duckbricks
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
duckbricks-0.1.0.tar.gz -
Subject digest:
c1bafabf16027f2da44b1f343e46aa6686e1624b0d60a60d879bd9d4e4534a0b - Sigstore transparency entry: 2294502252
- Sigstore integration time:
-
Permalink:
bmsuisse/duckbricks@53fa6670ee9ef5cd6abd56b65ae53bf99a4bc1d1 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/bmsuisse
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@53fa6670ee9ef5cd6abd56b65ae53bf99a4bc1d1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file duckbricks-0.1.0-py3-none-any.whl.
File metadata
- Download URL: duckbricks-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3a71fc3203a5c2fe18ca227c81049e49c85186b41dec4cb4537b731568bc68e
|
|
| MD5 |
1eb744efaca70f9159407630e0110dde
|
|
| BLAKE2b-256 |
6bccf9048a5e4b3502ed64584d5117ff4ddd26c6e1b1b9a084ac01143a815963
|
Provenance
The following attestation bundles were made for duckbricks-0.1.0-py3-none-any.whl:
Publisher:
release.yml on bmsuisse/duckbricks
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
duckbricks-0.1.0-py3-none-any.whl -
Subject digest:
c3a71fc3203a5c2fe18ca227c81049e49c85186b41dec4cb4537b731568bc68e - Sigstore transparency entry: 2294502266
- Sigstore integration time:
-
Permalink:
bmsuisse/duckbricks@53fa6670ee9ef5cd6abd56b65ae53bf99a4bc1d1 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/bmsuisse
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@53fa6670ee9ef5cd6abd56b65ae53bf99a4bc1d1 -
Trigger Event:
push
-
Statement type: