Skip to main content

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=true on the server. Against a server with it off, opening a session raises an OperationalError.

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

  • otel extra — each request emits a client span and injects a W3C traceparent, 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

duckhaven_sql_connector-0.1.0.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

duckhaven_sql_connector-0.1.0-py3-none-any.whl (28.1 kB view details)

Uploaded Python 3

File details

Details for the file duckhaven_sql_connector-0.1.0.tar.gz.

File metadata

  • Download URL: duckhaven_sql_connector-0.1.0.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for duckhaven_sql_connector-0.1.0.tar.gz
Algorithm Hash digest
SHA256 646cb66f88a1530ad0c4a0ae804ace2434bcf2ed1e7abb6aaf3c5c46c8475e93
MD5 be06f2d47cd3c67404e1e162b23f47c1
BLAKE2b-256 814a217a6d409eb5030fe40f5d3e6e07dd5d7798bdda18bc0c452455b85bd27e

See more details on using hashes here.

Provenance

The following attestation bundles were made for duckhaven_sql_connector-0.1.0.tar.gz:

Publisher: release.yml on tamasmrtn/duckhaven-clients

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file duckhaven_sql_connector-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for duckhaven_sql_connector-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 edb80c05b33357440c3ea6a06bd87ddbaa041b8cb1d77fc0cf76c5a916fc11e1
MD5 4964baba5fdc2abf1617ec994d299b56
BLAKE2b-256 501c5b144d63a09ab6e4bf16669ae2d142393ab0e472464967de7003dec63c2b

See more details on using hashes here.

Provenance

The following attestation bundles were made for duckhaven_sql_connector-0.1.0-py3-none-any.whl:

Publisher: release.yml on tamasmrtn/duckhaven-clients

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page