Pirkle — Query CSV and SQLite with PRQL
Pirkle is a command-line tool to query CSV and SQLite files using the PRQL language.
It loads CSV files into an in-memory SQLite database — allowing you to join them with other tables, apply filters, and export results in table or CSV format.
Features
- Query CSV files as structured tables
- Join CSV and SQLite files together
- Write expressive queries using PRQL
- Output as a pretty table, CSV, JSON, or logfmt
- Inspect the generated SQL
- View schema information for files
- Lightweight, fast, and written in Rust
Installation
Prebuilt binaries
Prebuilt binaries are available on the Releases page.
The macOS binaries are code-signed and notarized with Apple, but as a command-line tool, you may still need to:
-
Right-click the executable and choose "Open" the first time you run it
OR
-
Remove the quarantine attribute via Terminal:
From crates.io
From Source
Or install using Rust:
Usage
Basic Queries
# Query a CSV file. CSV files are auto-loaded as SQLite tables.
# Query a SQLite file (after generating with examples/make_sqlite.sh)
# Alternative syntax using -- delimiter
Reading from Standard Input
Pirkle supports reading CSV data from standard input, making it easy to pipe data from other commands:
# Pipe data into pirkle
|
# Use stdin with files
|
# Custom table name for stdin data
|
Key features:
- Auto-detection: Data on stdin is loaded as a table named "stdin"
- Explicit reference: Use the filename
stdinto read from stdin - Custom naming: Use
stdin:tablenamefor custom table names - Query from stdin: If no query is provided with
--queryor--, Pirkle will read the query from stdin:| - Multiple references: Use the same stdin data with different table names
|
Pirkle intelligently determines how to use stdin based on your command arguments, making it a flexible tool for data pipelines.
Viewing Schema Information
To see the structure of your tables:
# View schemas with the --schema flag
)
)
)
)
)
)
Show SQL without executing
You can use the --show-sql flag to see the SQL that would be generated without executing the query:
)
This also works with PRQL files:
)
)
Output formats
Default is a readable table format.
To output CSV:
Other supported formats:
# JSON Lines format
}
}
}
# logfmt format
id="1" name="John Smith" department="Engineering" age="32" salary="85000" country="USA"
id="3" name="Robert Johnson" department="Engineering" age="41" salary="92000" country="USA"
id="9" name="James Brown" department="Sales" age="39" salary="85000" country="USA"
Using PRQL files
You can use prewritten PRQL query files:
# Use a PRQL file directly with --query
Joining tables
To join tables, use the join operation:
Example Data
Included example files:
examples/employees.csv: Employee data with department, salary, and country informationexamples/departments.csv: Department names and IDsexamples/customers.csv,examples/orders.csv: Customer-order relationship dataexamples/queries/*.prql: Sample PRQL queries
License
MIT