CLI to conveniently run DuckDB SQL scripts with support for templating
Project description
Qck 🦆👩💻
Qck (pronounced "quack") is a CLI script to conveniently run DuckDB SQL scripts with support for Jinja templating.
🛠️ Installation
Use pip install qck to install. This will make available the qck
command-line tool.
🚀 Usage
Command Line Interface
The basic usage is to run a SQL file and display results in the terminal:
qck myquery.sql
Key command line options:
--limit N: Limit output to N rows (default: 99 rows)--to-parquet FILE: Save results to a Parquet file--to-csv FILE: Save results to a CSV file--interactive: Open Python shell with query results--verbose, -v: Print the generated SQL queryargs: Pass template parameters as key=value pairs
Examples:
# Limit output to 10 rows
qck myquery.sql --limit 10
# Save to Parquet with verbose output
qck myquery.sql --to-parquet results.parquet -v
# Pass template parameters
qck template.sql date=2024-01-01 region=EU
# Interactive mode
qck myquery.sql --interactive
# Pipe SQL from stdin (use - as filename)
echo "SELECT 42 as answer" | qck -
# With template parameters from stdin
echo "SELECT '{{ name }}' as greeting" | qck - name=World
Python API
You can use Qck programmatically in Python:
from qck import qck
# Basic query execution
rs = qck("myquery.sql")
# With template parameters
rs = qck("template.sql", params={"date": "2024-01-01"})
# Control output limit
rs = qck("myquery.sql", limit=1000)
# Print generated SQL
rs = qck("myquery.sql", print_query=True)
# Access results as pandas DataFrame
df = rs.df()
🖋️ Templating
Qck uses Jinja2 for SQL templating with some special features:
- Parameter substitution:
SELECT *
FROM orders
WHERE date = '{{ date }}'
- Python function imports:
-- Use the special 'import' variable to access Python functions
{% set files = import('glob.glob')('data/*.parquet') %}
{% for file in files %}
SELECT * FROM read_parquet('{{ file }}')
{% if not loop.last %}UNION ALL{% endif %}
{% endfor %}
- Control structures:
SELECT
customer_id,
{% if include_details %}
first_name,
last_name,
email,
{% endif %}
total_orders
FROM customers
- Custom Python functions:
-- Import and use your own functions
{% set helper = import('mymodule.helpers:format_date') %}
SELECT *
FROM events
WHERE date = '{{ helper(date) }}'
The import variable allows importing any Python module or function using:
- Module syntax:
import('module_name') - Function syntax:
import('module:function') - Nested syntax:
import('module.submodule:function')
🧪 Testing
To run the test suite:
# Install development dependencies
pip install -e .
pip install pytest
# Run tests
pytest test_qck.py -v
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 qck-2025.8.28.tar.gz.
File metadata
- Download URL: qck-2025.8.28.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a77c76f6511208df5e7deae617084ef2587a4671a876deef84547eca0e19fc53
|
|
| MD5 |
e1647a49bd1189322515761c7515a43b
|
|
| BLAKE2b-256 |
eee34d5294504439c49b736828918b30a35672592cd34c07356f63552d1cb5fc
|
File details
Details for the file qck-2025.8.28-py3-none-any.whl.
File metadata
- Download URL: qck-2025.8.28-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
031f3c77e8e133fa543b4821595faa2bcda484d86558e19e1b437838db9bfb94
|
|
| MD5 |
fd0ca941100c769d11fe2447f3462c35
|
|
| BLAKE2b-256 |
82cf7a5cc17f333f1f5704698303cc4ad9fea8663af1a97e448e25b39f427f21
|