Python SDK for DuckGresQL — DuckDB-compatible API for remote databases
Project description
DuckGresQL Python SDK
Python client for DuckGresQL — a DuckDB-compatible API for remote databases. Uses Arrow Flight SQL for fast query execution and a REST API for async job management.
Installation
Requires Python 3.11+
pip install duckgresql
With optional extras:
pip install duckgresql[pandas] # adds fetchdf() support
pip install duckgresql[all] # pandas + numpy
Quick Start
Synchronous
import duckgresql
conn = duckgresql.connect(
token="dkgql_your_api_token",
database="my_database",
)
# Execute a query
result = conn.execute("SELECT * FROM users LIMIT 10")
print(result.fetchall())
# Get a pandas DataFrame
df = conn.execute("SELECT * FROM sales").fetchdf()
# DML
result = conn.execute("INSERT INTO users (name) VALUES ('Alice')")
print(result.rowcount) # affected rows
conn.close()
Async
import asyncio
import duckgresql
async def main():
conn = await duckgresql.connect_async(
token="dkgql_your_api_token",
database="my_database",
)
result = await conn.execute("SELECT * FROM users")
print(result.fetchall())
await conn.close()
asyncio.run(main())
Context Manager
with duckgresql.connect(token="...", database="...") as conn:
result = conn.execute("SELECT 1")
print(result.fetchone())
Async Jobs (Long-Running Queries)
conn = duckgresql.connect(token="...", database="...")
job = conn.execute_async("SELECT * FROM very_large_table")
print(f"Job submitted: {job.job_id}")
# Poll until done (with exponential backoff)
result = job.result(timeout=600)
print(result.fetchall())
Connection Parameters
| Parameter | Default | Description |
|---|---|---|
token |
required | API token (dkgql_…) |
database |
required | Database name or UUID |
Result Methods
| Method | Returns | Description |
|---|---|---|
fetchone() |
tuple | None |
Next row |
fetchmany(size) |
list[tuple] |
Up to size rows |
fetchall() |
list[tuple] |
All remaining rows |
fetchdf() |
DataFrame |
Pandas DataFrame (requires pandas) |
fetchnumpy() |
dict[str, ndarray] |
NumPy arrays (requires numpy) |
fetch_arrow_table() |
pyarrow.Table |
Zero-copy Arrow table |
Result Properties
| Property | Type | Description |
|---|---|---|
description |
list | None |
DB-API 2.0 column metadata |
rowcount |
int |
Row count or affected rows |
columns |
list[str] |
Column names |
Architecture
- Arrow Flight SQL (gRPC) — Primary transport for
execute(). Fast, columnar, zero-copy. - REST API — Used only for
execute_async()(job submission/polling), since Flight SQL has no native job queue pattern.
Both transports authenticate via the same API token. Flight SQL uses BasicAuth handshake; REST uses the /connect endpoint to exchange the token for a session token.
Developing the SDK? See CONTRIBUTING.md for setup, testing, building, and publishing.
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 duckgresql-1.5.1.2.tar.gz.
File metadata
- Download URL: duckgresql-1.5.1.2.tar.gz
- Upload date:
- Size: 63.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20e5cb7df13ddfccc33ad0af00cfcc0c8d01927e754bfd996c996fce48250ec6
|
|
| MD5 |
1d5e3907b152f31f6a805c76a66b628a
|
|
| BLAKE2b-256 |
b45e85e853af4680d66e37d9a08c52ccb50a49a49af05aa50b8d6301a5932eef
|
Provenance
The following attestation bundles were made for duckgresql-1.5.1.2.tar.gz:
Publisher:
release.yml on Duckgresql/python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
duckgresql-1.5.1.2.tar.gz -
Subject digest:
20e5cb7df13ddfccc33ad0af00cfcc0c8d01927e754bfd996c996fce48250ec6 - Sigstore transparency entry: 1187905418
- Sigstore integration time:
-
Permalink:
Duckgresql/python-sdk@df8cc13affa613c15f03d34b20ac7c7ec298b243 -
Branch / Tag:
refs/tags/v1.5.1.2 - Owner: https://github.com/Duckgresql
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@df8cc13affa613c15f03d34b20ac7c7ec298b243 -
Trigger Event:
push
-
Statement type:
File details
Details for the file duckgresql-1.5.1.2-py3-none-any.whl.
File metadata
- Download URL: duckgresql-1.5.1.2-py3-none-any.whl
- Upload date:
- Size: 19.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74cc242a9c931457f7ee49746ebdec34936ec6e4cb9f5c53160fe3c8951ebe5f
|
|
| MD5 |
130ca097c4694ac61babf11b9bdf5a08
|
|
| BLAKE2b-256 |
93b8e1223057cefb8024480bb803904b82f158889d5a4dbc878f09be38e44816
|
Provenance
The following attestation bundles were made for duckgresql-1.5.1.2-py3-none-any.whl:
Publisher:
release.yml on Duckgresql/python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
duckgresql-1.5.1.2-py3-none-any.whl -
Subject digest:
74cc242a9c931457f7ee49746ebdec34936ec6e4cb9f5c53160fe3c8951ebe5f - Sigstore transparency entry: 1187905502
- Sigstore integration time:
-
Permalink:
Duckgresql/python-sdk@df8cc13affa613c15f03d34b20ac7c7ec298b243 -
Branch / Tag:
refs/tags/v1.5.1.2 - Owner: https://github.com/Duckgresql
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@df8cc13affa613c15f03d34b20ac7c7ec298b243 -
Trigger Event:
push
-
Statement type: