Skip to main content

dr-duck

DuckDB and MotherDuck utilities with autocomplete-friendly helpers.

Installation

pip install dr-duck

Or with uv:

uv add dr-duck

Connection Helpers

from dr_duck import open_motherduck_connection, open_local_connection

# MotherDuck (reads MOTHERDUCK_TOKEN from env)
conn = open_motherduck_connection()

# Local DuckDB file
conn = open_local_connection("my_data.duckdb")

# In-memory
conn = open_local_connection()  # defaults to :memory:

# With .env file and optional secrets
conn = open_local_connection(
    "data.duckdb",
    env_file=".env",
    hf_token="...",      # or reads HF_TOKEN from env
    s3_key_id="...",     # or reads AWS_ACCESS_KEY_ID from env
    s3_secret="...",     # or reads AWS_SECRET_ACCESS_KEY from env
)

Secret Setup

from dr_duck import setup_hf_secret, setup_s3_secret

# Set up HuggingFace secret (enables hf:// URLs)
setup_hf_secret(conn, token="...")  # or reads HF_TOKEN from env

# Set up S3 secret
setup_s3_secret(
    conn,
    key_id="...",        # or reads AWS_ACCESS_KEY_ID
    secret="...",        # or reads AWS_SECRET_ACCESS_KEY
    region="us-west-2",  # or reads AWS_REGION, defaults to us-east-1
    endpoint="...",      # optional, for S3-compatible services
)

Query Helpers

from dr_duck import query_to_df, query_hf, query_parquet, list_tables, describe_table

# Run any SQL, get DataFrame
df = query_to_df(conn, "SELECT * FROM my_table LIMIT 10")

# Query HuggingFace dataset
df = query_hf(conn, "username/dataset", "data/*.parquet")
df = query_hf(conn, "username/dataset", "train.parquet", sql="SELECT * FROM {table} WHERE x > 5")

# Query parquet file (local or remote)
df = query_parquet(conn, "s3://bucket/data.parquet")
df = query_parquet(conn, "data/*.parquet", sql="SELECT col1, col2 FROM {table}")

# Schema inspection
tables = list_tables(conn)
schema = describe_table(conn, "my_table")

DataFrame Helpers

from dr_duck import insert_df, create_table_from_df

# Insert DataFrame into existing table
insert_df(conn, df, "my_table")

# Create new table from DataFrame
create_table_from_df(conn, df, "new_table")
create_table_from_df(conn, df, "new_table", replace=True)  # CREATE OR REPLACE

Environment Variables

  • MOTHERDUCK_TOKEN - Required for open_motherduck_connection
  • HF_TOKEN - Enables hf:// URLs in DuckDB queries
  • AWS_ACCESS_KEY_ID - For S3 access
  • AWS_SECRET_ACCESS_KEY - For S3 access
  • AWS_REGION - S3 region (defaults to us-east-1)

License

MIT

Metadata

Release files for dr-duck 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dr-duck 0.1.0
File Size Uploaded
dr_duck-0.1.0.tar.gz 5.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dr-duck 0.1.0
File Interpreter ABI Platform
dr_duck-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.2 kB

Release files / dr_duck-0.1.0.tar.gz

Download URL dr_duck-0.1.0.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5670b8a01fdeedd9a9845f5e639584a2779585f92340f77f6d839130a385d5ca
BLAKE2b-256 checksum
How to use checksums
8bcf20503c47d536ddb68eb47632a5e8fd6d11488dd7d5566f2070c100b3f5a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.7

Release files / dr_duck-0.1.0-py3-none-any.whl

Download URL dr_duck-0.1.0-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
00e2828df4840a0a37f567b651c27ce7432703bb071e65589988f2e6391eb577
BLAKE2b-256 checksum
How to use checksums
79ba4945f8886f88f045d7e18dc403eed29d1e65a96b6f7c233cc2f535af1d6c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.7

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page