DB-API 2.0 client for DuckHaven's SQL session/statement API
Project description
duckhaven-sql-connector
A PEP 249 (DB-API 2.0) Python client for DuckHaven's SQL session API.
It is a pure HTTP client of DuckHaven's public REST API: it authenticates with a
DuckHaven Personal Access Token (dh_pat_…), opens a SQL session bound to one compute
agent, runs statements against that session's persistent DuckDB connection, and fetches
results. It never talks to a compute node directly and depends on no DuckHaven server
internals.
This connector is the shared transport that dbt-duckhaven, the dlt duckhaven
destination, a future CLI, and Airflow operators build on.
Install
pip install duckhaven-sql-connector
# optional extras:
pip install "duckhaven-sql-connector[arrow]" # client-side Arrow tables
pip install "duckhaven-sql-connector[otel]" # OpenTelemetry trace propagation
Usage
from duckhaven_sql_connector import connect
with connect(
host="https://duckhaven.internal",
workspace="analytics",
token="dh_pat_…",
catalog="sales", # optional default catalog
# agent="…-uuid-…", # optional explicit compute (an agent UUID); omit to auto-pick
) as conn:
with conn.cursor() as cur:
cur.execute("SELECT ? AS n", [1]) # qmark params, rendered safely client-side
print(cur.description, cur.fetchall())
A runnable version is in examples/quickstart.py.
Note: The DuckHaven SQL session surface is disabled unless the operator sets
SQL_SESSIONS_ENABLED=trueon the server. Against a server with it off, opening a session raises anOperationalError.
Errors
Failures raise the standard PEP 249 exceptions,
carrying the server's code/status_code/detail:
ProgrammingError— a rejected statement (statement_not_allowed), a denied grant, or a missing object.OperationalError— an unavailable/disconnected agent, a reaped or closed session (reconnect), a timeout, or the session surface being disabled.MaxRetryDurationError(a subtype) is raised when retries exhaust the configured time budget.InterfaceError— bad connection configuration or a malformed response.
Idempotent requests (poll/fetch/cancel) are retried on transient failures with capped
exponential backoff; a server Retry-After header is honored, and retries are bounded by
both a max-attempt count and a total-time budget (RetryPolicy.max_elapsed). Statement
submits are never auto-retried.
Metadata
For relation introspection (as dbt and BI tools need), the cursor exposes metadata methods
that query the server's information_schema; fetch the rows as usual:
cur.tables(schema_name="public")
for catalog, schema, name, table_type in cur.fetchall():
...
# also: cur.catalogs(), cur.schemas(catalog=…), cur.columns(table_name=…)
Arrow results
With the arrow extra, fetch results as a pyarrow.Table:
cur.execute("SELECT * FROM sales.orders")
table = cur.fetch_arrow_table()
Observability
otelextra — each request emits a client span and injects a W3Ctraceparent, so client spans join the DuckHaven server trace. It is a no-op when the extra isn't installed.- Hooks — pass
connect(..., hooks=Hooks(...))to observe request timings, retries, and rows fetched without any OpenTelemetry dependency (a client library runs no metrics server).
Compatibility
The exact server endpoints and fields this client depends on are pinned in
contract/duckhaven-openapi.subset.json and checked
by the contract test. Regenerate it against a running server with
make refresh-contract HOST=https://duckhaven.internal to detect API drift early.
License
Apache-2.0.
Project details
Release history Release notifications | RSS feed
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 duckhaven_sql_connector-0.2.0.tar.gz.
File metadata
- Download URL: duckhaven_sql_connector-0.2.0.tar.gz
- Upload date:
- Size: 23.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2883ff7433200d3033e81acbeae7e52d120bb4b69953a5af43176b58377f85ee
|
|
| MD5 |
c52b5c09bf993054a56c8de4df149ad2
|
|
| BLAKE2b-256 |
607a42d4ca868bb0591eebaaf4d11768cf2771d567656f12b180c97871b78756
|
Provenance
The following attestation bundles were made for duckhaven_sql_connector-0.2.0.tar.gz:
Publisher:
release.yml on tamasmrtn/duckhaven-clients
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
duckhaven_sql_connector-0.2.0.tar.gz -
Subject digest:
2883ff7433200d3033e81acbeae7e52d120bb4b69953a5af43176b58377f85ee - Sigstore transparency entry: 2196993956
- Sigstore integration time:
-
Permalink:
tamasmrtn/duckhaven-clients@d5e06cbda58e521e82b5b30e64c90fdcc5b5ed4a -
Branch / Tag:
refs/tags/sql-connector-v0.2.0 - Owner: https://github.com/tamasmrtn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d5e06cbda58e521e82b5b30e64c90fdcc5b5ed4a -
Trigger Event:
push
-
Statement type:
File details
Details for the file duckhaven_sql_connector-0.2.0-py3-none-any.whl.
File metadata
- Download URL: duckhaven_sql_connector-0.2.0-py3-none-any.whl
- Upload date:
- Size: 28.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0377340544c7e4982e08805dab1497028a68a1780137c11b136278be667621c
|
|
| MD5 |
44e8cfe60606979070d8089ed804f7c4
|
|
| BLAKE2b-256 |
37527fcad8db463925be46c204ec65f0ce7711628f034a173defbfd50d131d1d
|
Provenance
The following attestation bundles were made for duckhaven_sql_connector-0.2.0-py3-none-any.whl:
Publisher:
release.yml on tamasmrtn/duckhaven-clients
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
duckhaven_sql_connector-0.2.0-py3-none-any.whl -
Subject digest:
b0377340544c7e4982e08805dab1497028a68a1780137c11b136278be667621c - Sigstore transparency entry: 2196994074
- Sigstore integration time:
-
Permalink:
tamasmrtn/duckhaven-clients@d5e06cbda58e521e82b5b30e64c90fdcc5b5ed4a -
Branch / Tag:
refs/tags/sql-connector-v0.2.0 - Owner: https://github.com/tamasmrtn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d5e06cbda58e521e82b5b30e64c90fdcc5b5ed4a -
Trigger Event:
push
-
Statement type: