Skip to main content

QuackSQL

A simple Python wrapper for DuckDB that allows you to load and execute SQL queries from files with a clean, Pythonic interface.

Installation

pip install quacksql

Quick Start

import quacksql

# Connect to an in-memory database (default)
quacksql.connect()

# Or connect to a file
quacksql.connect('my_database.duckdb')

# Load SQL queries from a directory
quacksql.module('./queries')

# Execute a query (assumes you have a file queries/get_users.sql)
results = quacksql.get_users()

# Get results as a pandas DataFrame
df = quacksql.get_users().df()

# Pass parameters to queries
results = quacksql.get_user_by_id(user_id=123).df()

Features

  • Simple API: Load SQL files and execute them as Python methods
  • Pandas Integration: Easy conversion to DataFrames with .df()
  • Parameter Support: Pass parameters to queries using positional or keyword arguments
  • DuckDB Power: Full access to DuckDB's analytical capabilities

Usage

Loading SQL Modules

Place your SQL files in a directory:

queries/
├── get_users.sql
├── get_orders.sql
└── update_inventory.sql

Load them in Python:

import quacksql

quacksql.connect('mydb.duckdb')
quacksql.module('./queries')

# Now you can call any query as a method
users = quacksql.get_users().df()
orders = quacksql.get_orders().df()

Working with Parameters

SQL file (queries/get_user.sql):

SELECT * FROM users WHERE user_id = ?

Python code:

user = quacksql.get_user(123).fetchone()

Or with named parameters:

SELECT * FROM users WHERE name = $name AND age > $min_age
users = quacksql.get_users(name='Alice', min_age=25).df()

Query Results

All queries return a QueryResult object with multiple methods:

result = quacksql.my_query()

# Get as pandas DataFrame
df = result.df()

# Get all rows as list of tuples
rows = result.fetchall()

# Get first row
first = result.fetchone()

# Get n rows
some = result.fetchmany(10)

# Iterate over results
for row in result:
    print(row)

Requirements

  • Python >= 3.8
  • DuckDB
  • Pandas

License

MIT License - see LICENSE file for details

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Metadata

Release files for quacksql 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 quacksql 0.1.0
File Size Uploaded Provenance
quacksql-0.1.0.tar.gz 4.8 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 9.5 kB

Release files / quacksql-0.1.0.tar.gz

Download URL quacksql-0.1.0.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
4ae34aac4b94ec7c3af6eb1e157b14a08366aea3b7d1c109e28a1122795645f2
BLAKE2b-256 checksum
How to use checksums
6d5d93682e77c9f27d85f34042f94aead7cfc61429ec80b5a06c0ebb07531fdd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.6

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

Download URL quacksql-0.1.0-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
18e8bca3d3690cd23915403a6610c10f996f223fb6fc5c57619a987e713f17e4
BLAKE2b-256 checksum
How to use checksums
4184baae5e1ed40560df1181ec3c2aef99ed83c1f7379db89de9117d45f82d88
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.6

Security for quacksql 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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