Skip to main content

Simple MotherDuck connection utilities

Project description

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

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

dr_duck-0.1.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

dr_duck-0.1.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dr_duck-0.1.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.7

File hashes

Hashes for dr_duck-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5670b8a01fdeedd9a9845f5e639584a2779585f92340f77f6d839130a385d5ca
MD5 9b3046715513d866015303736415052b
BLAKE2b-256 8bcf20503c47d536ddb68eb47632a5e8fd6d11488dd7d5566f2070c100b3f5a1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dr_duck-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.7

File hashes

Hashes for dr_duck-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 00e2828df4840a0a37f567b651c27ce7432703bb071e65589988f2e6391eb577
MD5 8cee572a72f18eff64e12e889c3f6937
BLAKE2b-256 79ba4945f8886f88f045d7e18dc403eed29d1e65a96b6f7c233cc2f535af1d6c

See more details on using hashes here.

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