Plot the output of duckdb query
Project description
Duck Plot CLI
A command-line tool for visualizing SQL query results using DuckDB and Altair charts.
Installation
Install this tool using pip:
pip install duck-plot
or run the cli with uvx in a temporary virtual environment:
uvx duck-plot ...
Features
- Execute SQL queries against DuckDB databases or in-memory data
- Create line or bar charts from query results
- Display query results in a rich formatted table
- Support for piped input and command-line arguments
- Interactive visualizations in the browser
Usage
Basic Query Visualization
Create a line chart from query results:
duck-plot "SELECT date, sales FROM 'sales.csv'" -x date -y sales
Create a bar chart:
duck-plot "SELECT category, count(*) as total FROM 'sales.csv' GROUP BY 1" -x category -y total --type bar
Using a DuckDB Database
Query an existing DuckDB database:
duck-plot "SELECT * FROM monthly_sales" -x month -y revenue --db sales.duckdb
Piping Queries
Use heredoc for complex queries:
cat << EOF | duck-plot -x month -y total_sales --type bar
SELECT
date_trunc('month', date) as month,
sum(sales) as total_sales
FROM sales
GROUP BY 1
ORDER BY 1
EOF
Query-Only Mode
You have the option to only display results without creating a chart:
duck-plot "SELECT * FROM sales LIMIT 5" --query-only
or use a pipe:
echo "SELECT * FROM 'sales.parquet'" | duck-plot --query-only --db sales.duckdb
Options
Arguments:
query SQL query to execute [optional if piping input]
Options:
-x, --x TEXT Column name for X-axis
-y, --y TEXT Column name for Y-axis
-t, --type TEXT Type of chart (line or bar) [default: line]
-d, --db TEXT Path to DuckDB database file [optional]
-q, --query-only Output query results to stdout and skip chart creation
--help Show this message and exit
Examples
Analyzing Time Series Data
duck-plot "
SELECT
date,
moving_average(price, 7) as price_ma
FROM 'stock_prices.csv'
WHERE symbol = 'AAPL'
ORDER BY date
" -x date -y price_ma
Comparing Categories
duck-plot "
SELECT
category,
sum(revenue) as total_revenue
FROM 'sales.csv'
GROUP BY category
ORDER BY total_revenue DESC
LIMIT 10
" -x category -y total_revenue --type bar
Interactive Data Exploration
# First view the available columns
duck-plot "FROM dataset LIMIT 1" --query-only
# Then create visualizations based on the columns
duck-plot "FROM dataset" -x timestamp -y temperature
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Development
To contribute to this tool, first checkout the code. Then create a new virtual environment:
cd duck-plot
python -m venv venv
source venv/bin/activate
Now install the dependencies and test dependencies:
pip install -e '.[test]'
To run the tests:
python -m pytest
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 duck_plot-0.12.tar.gz.
File metadata
- Download URL: duck_plot-0.12.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e88c489dff22d1af27a93b1cf152a3308eeee5e7dd869922da1e232acd59df8
|
|
| MD5 |
b637b6a90ec49f2c50c3700a81430a55
|
|
| BLAKE2b-256 |
56cc1ef4f01e0fea884361aad4b852d360d51306a5734313293638e99b823c67
|
Provenance
The following attestation bundles were made for duck_plot-0.12.tar.gz:
Publisher:
publish.yml on LVG77/duck-plot
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
duck_plot-0.12.tar.gz -
Subject digest:
9e88c489dff22d1af27a93b1cf152a3308eeee5e7dd869922da1e232acd59df8 - Sigstore transparency entry: 162482804
- Sigstore integration time:
-
Permalink:
LVG77/duck-plot@a6eccb2be7cd00c7b842a958ef9f95c97814498b -
Branch / Tag:
refs/tags/0.12 - Owner: https://github.com/LVG77
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a6eccb2be7cd00c7b842a958ef9f95c97814498b -
Trigger Event:
release
-
Statement type:
File details
Details for the file duck_plot-0.12-py3-none-any.whl.
File metadata
- Download URL: duck_plot-0.12-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c57e21f3a54b051abefcebca410bd732bafdc53d83faf0b192470bb243433e92
|
|
| MD5 |
2af3fabaf9e09f30d6342d84c26eff30
|
|
| BLAKE2b-256 |
e0903cc4fc926ff8a04e50fb3add69da6b7c7a8859e4b47effbc95e782fcd514
|
Provenance
The following attestation bundles were made for duck_plot-0.12-py3-none-any.whl:
Publisher:
publish.yml on LVG77/duck-plot
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
duck_plot-0.12-py3-none-any.whl -
Subject digest:
c57e21f3a54b051abefcebca410bd732bafdc53d83faf0b192470bb243433e92 - Sigstore transparency entry: 162482806
- Sigstore integration time:
-
Permalink:
LVG77/duck-plot@a6eccb2be7cd00c7b842a958ef9f95c97814498b -
Branch / Tag:
refs/tags/0.12 - Owner: https://github.com/LVG77
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a6eccb2be7cd00c7b842a958ef9f95c97814498b -
Trigger Event:
release
-
Statement type: