Design#
How it works#
login()/client() -> browse (SDK) -> describe(name) -> fetch(name, ...)
|
Unity Catalog: table metadata -> temporary read credentials + storage path
|
DuckDB (Delta extension) reads the Delta files -> local Parquet file
The Databricks SDK signs in with its browser OAuth flow (
auth_type="external-browser") and lists catalogs, schemas and tables.For a fetch, Unity Catalog’s
temporary-table-credentialsAPI returns short-lived, read-only AWS credentials and the table’s S3 path.DuckDB’s Delta extension reads that path, applies the column and row selection, and writes Parquet through a temporary file that is renamed on success.
Modules#
Module |
Responsibility |
|---|---|
|
Workspace URL ( |
|
|
|
|
|
The public exception hierarchy. |
Decisions#
The goal was the fewest dependencies and the least code.
Engine: DuckDB. One dependency reads the Delta log including
deletionVectors,v2CheckpointandcolumnMapping(the features of Lakeflow tables), pushes column and filter selection down, reports exact file sizes (delta_list_filesplusread_blob) and writes Parquet. Rejected: Polarsscan_deltaand delta-rs’s pyarrow reader both refuse these tables (“requires reader features v2Checkpoint…”, re-verified with polars 2.1.0 and deltalake 1.6.6). Daft and DuckDB’sunity_catalogATTACH failed in earlier exploration and were not retested. delta-rs’s SQL engine reads them but was not pursued: DuckDB already covers everything with one dependency. Spark with the Unity Catalog connector was not tested: it needs Java 17+ and documents only token or OAuth M2M auth, i.e. a shared secret.Format: Parquet. Typed, compressed and readable by every framework, so the package stays framework-agnostic. Rejected: returning a DataFrame (forces a framework), copying raw Delta files (breaks on deletion vectors), CSV (loses types).
Auth: the SDK’s own browser OAuth. Uses the built-in
databricks-clipublic OAuth client, so per-person setup is onelogincall and no CLI install. Rejected: the Databricks CLI profile (separate install and login), personal access tokens and OAuth M2M (secrets). The workspace URL is saved to~/.config/databricks-external-access/host, only after sign-in succeeds, andDATABRICKS_HOSToverrides it.Install: PyPI. Published by the release workflow through trusted publishing (GitHub’s OIDC identity, no stored token); every release is also a git tag and a GitHub Release with the wheel and sdist attached. Rejected: GitHub Packages (it has no Python registry).
Import name
databricks_external_access. It avoids thedatabricksnamespace, whichdatabricks-sdkowns (databricks.sdk).One error hierarchy. Callers can catch
Error, or a subclass to react to one case (for example skipUnsupportedTablewhile looping over tables).
Trade-offs#
Pipeline bookkeeping columns. Lakeflow stores extra columns in a table’s files that the logical table hides: streaming tables written by
apply_changeskeep__DeleteVersion,__MEETS_DROP_EXPECTATIONSand others, and some materialized views keep helper columns such as__DECOMP_GENERATED_count_0.fetchreturns only the columns Unity Catalog declares. Forapply_changestables Unity Catalog also defines the logical table by dropping deleted and expectation-failing rows (itsspark.internal.streaming_table.reconciliation_queryproperty);fetchapplies those two row filters when it sees the columns. This relies on an internal Databricks convention, which is why the integration test compares the fetched columns with the declared ones.Read credentials expire after at most an hour. A transfer that outlives them fails with an S3 access error; fetch a smaller slice.
The size shown is the whole table, an upper bound for a slice.
fetchprints to stderr (the size line) rather than logging, because telling the user the size is a requirement, not a diagnostic.whereis a DuckDB SQL predicate, not sanitised. It runs on the user’s machine with the user’s own credentials.No Databricks compute is used, so the work is bounded by the user’s machine and network.
Extending the package#
The seams are in place; build them when a consumer exists, not before.
Databricks Connect (data too large for a laptop): authentication is already one function,
_workspace.client(), whoseconfiga Connect session can reuse. Add a function besidefetchand keepfetch.pythe only module that knows about engines.Another cloud:
fetch._credentialsandfetch._connectare the only places that assume AWS credentials and S3.Another output format:
fetch._writeis the only place that writes a file.New table kinds:
fetch._READABLE_KINDS/_READABLE_FORMATSand the pipeline handling in_credentials.
Anything that adds a runtime dependency, an option kept “just in case”, or a second way to do an existing thing should be discussed in an issue first (see CONTRIBUTING.md).