Tentang
executes SQL against CSV, TSV, LTSV, JSON, JSONL, Parquet, Microsoft Excel™ , ACH, and Fedwire files with shell.
Data dan analisisPertumbuhan bintang terukur
- dalam 24 jam
- +1
- dalam 7 hari
- +1
- dalam 15 hari
- +1
- dalam 1 bulan
- Pembaruan tertunda
Perubahan bersih pada periode yang tumpang tindih, bukan total harian. Pengukuran yang belum tersedia dibiarkan kosong. Bintang menunjukkan perhatian, bukan kualitas.
README.md
Aslisqly
sqly runs SQL against CSV, TSV, LTSV, JSON, JSONL, Parquet, Excel, ACH, and Fedwire files. It loads them into an in-memory SQLite3 database, so joins, CTEs, window functions, and aggregates work across formats in one query. Compressed files (.gz, .bz2, .xz, .zst, .z, .snappy, .s2, .lz4) are read transparently.
Documentation: https://nao1215.github.io/sqly/

Try it in 30 seconds
If you have Go, paste this:
printf 'name,dept,salary\nalice,eng,120\nbob,sales,90\ncarol,eng,140\n' > staff.csv
go run github.com/nao1215/sqly@latest --sql "SELECT dept, ROUND(AVG(salary)) AS avg FROM staff GROUP BY dept" staff.csv
+-------+-----+
| dept | avg |
+-------+-----+
| eng | 130 |
| sales | 90 |
+-------+-----+
The file is the table: staff.csv became staff, with no schema to declare and no import step.
Why sqly?
| You want | Use |
|---|---|
| A field-oriented text processor for logs and columns | awk, Miller |
| A CSV-native SQL dialect with its own engine and cursors | csvq |
| SQL over CSV/TSV/JSON with a choice of backend engines | trdsql |
| SQL over CSV with long-standing, mature tooling | q, textql |
| Analytics on data larger than memory, or on files in S3 | DuckDB |
| SQL over files, with an interactive shell, cross-format joins, and write-back | sqly |
DuckDB is faster and has the richer SQL. sqly adds .save --in-place for an edited CSV or Excel file, ACH, Fedwire and LTSV input, Shift-JIS and EUC-JP files saved in their own encoding, and MySQL, PostgreSQL or GoogleSQL syntax with --dialect.
Install
go install github.com/nao1215/sqly@latest
brew install nao1215/tap/sqly
The install page covers the AUR package, aqua, mise, the prebuilt binaries on the release page, and verifying a release. sqly runs on Windows, macOS, and Linux; building from source needs Go 1.26.11 or later.
Recipes
Look at a file you have never seen
--inspect prints the tables a file becomes, their columns, and their row counts as JSON, so jq can read it too. It prints no data rows.
sqly --inspect user.csv
{
"schema_version": 1,
"sqly_version": "v1.0.0",
"tables": [
{
"name": "user",
"source": "/home/nao/data/user.csv",
"row_count": 3,
"columns": [
{ "name": "user_name", "type": "TEXT", "nullable": true, "primary_key": false },
{ "name": "identifier", "type": "INTEGER", "nullable": true, "primary_key": false }
],
"sample_rows": []
}
]
}
--inspect-sample N adds at most N rows per table. The JSON Schema and the compatibility policy are on the reference page.

Join two files, of any format, in one query
The file is the table, whatever the format: a gzipped CSV and a Parquet file join like two tables in one database.
sqly --sql "SELECT u.user_name, i.position
FROM user u JOIN identifier i ON u.identifier = i.id" user.csv.gz identifier.parquet
+-----------+-----------+
| user_name | position |
+-----------+-----------+
| booker12 | developrt |
| jenkins46 | manager |
| smith79 | neet |
+-----------+-----------+

Convert between formats
The destination's extension picks the format; --output-format names it when the extension cannot.
sqly --output user.json --sql "SELECT * FROM user" user.csv
sqly --output user.xlsx --sql "SELECT * FROM user" user.csv
Output sql result to user.json (output mode=json)

Query JSON and JSONL
A JSON file becomes one table with a data column; SQLite's json_extract() reaches into it.
sqly --sql "SELECT json_extract(data, '$.name') AS name,
json_extract(data, '$.city') AS city FROM sample" sample.jsonl
+---------+--------+
| name | city |
+---------+--------+
| Alice | Tokyo |
| Bob | Osaka |
| Charlie | Nagoya |
+---------+--------+

Pipe the result into another tool
Use jsonl for jq and tsv for cut/awk/sort. jsonl writes only the rows; tsv writes a header line first, which the next tool reads as data unless it skips it.
sqly --output-format jsonl --sql "SELECT user_name, identifier FROM user" user.csv | jq -r '.user_name'
sqly --output-format tsv --sql "SELECT status, path FROM logs" logs.csv | cut -f1 | sort -rn | head -n 1
{"user_name":"booker12","identifier":1}
{"user_name":"jenkins46","identifier":2}
Load a directory, a URL, or standard input
sqly ./data --sql "SELECT * FROM users"
sqly --allow-remote --sql "SELECT * FROM user" https://example.com/user.csv
cat user.csv | sqly --stdin-format csv --sql "SELECT COUNT(*) FROM stdin"
A URL needs --allow-remote; without it sqly makes no HTTP request. The flag is
not a sandbox or an SSRF defense: it decides whether a request happens, not where
it may go. See the formats page.

Rank, window, aggregate
SQLite is the engine, so its whole query language is available, including window functions, CTEs, and json_*.
sqly --sql "SELECT actor, RANK() OVER (ORDER BY total_gross DESC) AS rank FROM actor" actor.csv
+-------------------+------+
| actor | rank |
+-------------------+------+
| Harrison Ford | 1 |
| Samuel L. Jackson | 2 |
| Morgan Freeman | 3 |
+-------------------+------+

Write MySQL, PostgreSQL, or BigQuery syntax
sqly --dialect postgresql --sql "SELECT user_name, identifier::text FROM \"user\" WHERE user_name ILIKE 'b%'" user.csv
--dialect translates syntax to SQLite. Constructs with no SQLite equivalent are rejected by name; the dialects page lists them and the known divergences.
Run SQL or a sqly script from a file
sqly --sql-file examples/report.sql examples/data/sales.csv
sqly --script-file examples/update.sqly examples/data/sales.csv
--sql-file takes SQL only; a dot-command in it is a usage error. --script-file
takes what the shell takes, SQL and dot-commands, so use it when the script has a
side effect such as .save. --script-file rejects
--output; use .dump inside the script instead.

Both are runnable in examples/, and the
cookbook has more recipes.
The shell
sqly with no --sql opens a REPL with context-aware tab completion for keywords, tables, columns, and paths, history across sessions, and dot-commands for what SQL has no syntax for.

sqly:~/data(table)$ .import user.csv
sqly:~/data(table)$ SELECT user_name FROM user
...> WHERE identifier = 1;
sqly:~/data(table)$ .edit
sqly:~/data(table)$ .mode json
sqly:~/data(json)$ .save ./out
.edit opens the last statement in $EDITOR, .theme picks a
theme, and .help lists every command; the
shell page documents them.
Write changes back
A session is in-memory only. .save writes the tables the session changed back
out, from the shell or from a script piped to sqly:

printf "UPDATE user SET first_name = 'Rachelle' WHERE identifier = 1;\n.save ./out\n" | sqly user.csv
.save DIR writes copies into DIR; .save --in-place overwrites the sources.
Format and compression are preserved, and a save covering several files is
all-or-nothing. See the shell page for
details. To write a query result to a file, use --output instead.
Formats
| Format | Extensions | Becomes |
|---|---|---|
| CSV / TSV / LTSV | .csv .tsv .ltsv |
one table, columns from the header |
| JSON / JSONL | .json .jsonl |
one table with a data column; query with json_extract() |
| Parquet | .parquet |
one table |
| Excel | .xlsx |
one table per sheet, named file_sheet; only the sheets the workbook shows, unless --include-hidden-sheets |
| ACH | .ach |
several tables (_file_header, _batches, _entries, _addenda) |
| Fedwire | .fed |
one _message table |
Multiple inputs are loaded atomically: if one file cannot be read, none of them are imported and the run exits 3. See the cookbook.
All except ACH and Fedwire also read the compression extensions above. Text inputs without a BOM decode as UTF-8, or as Shift-JIS, EUC-JP, ISO-2022-JP, or UTF-16 with --encoding. See Formats.
Flags
sqly has no subcommands. sqly --help lists the flags by group, and the reference lists every flag, the table name rules, and the exit codes.
Limitations
sqly runs each statement in its own transaction on an in-memory database, so it rejects these SQLite statements with an error:
- Explicit transaction control:
BEGIN,COMMIT,ROLLBACK,SAVEPOINT,RELEASE VACUUM/VACUUM INTO, andATTACH/DETACH DATABASE- DCL such as
GRANT/REVOKE
Benchmark
The Benchmark page compares sqly, trdsql, csvq, textql and DuckDB, measured with himorime. The per-PR regression suite is in bench/README.md.
Testing
| Technique | Bug class caught here |
|---|---|
| Unit and golden tests (main_test.go, testdata/golden) | A flag or an output format that prints something other than it did |
| End-to-end specs with atago (e2e/atago) | The built binary behaving differently from the documentation: exit codes, stderr, files written back, the interactive shell over a pty |
| Snapshot specs (e2e/atago/snapshot.atago.yaml) | A change in a whole rendered table that a line-by-line assertion would miss |
| Property-based state machine tests (shell/state_machine_property_test.go) | A sequence of edits and saves that leaves a file or the completion schema out of step with the database |
| Metamorphic tests (main_property_test.go) | The same table answering a query differently when it comes as TSV, LTSV or a compressed CSV |
| Differential tests (main_property_test.go) | sqly printing other rows or values than the database it loaded answers with |
| Fuzzing (shell/batch_fuzz_test.go, infrastructure/sql_property_test.go) | A crash or a broken identifier on input sqly did not expect |
| Mutation testing (.github/workflows/mutation.yml) | A test that runs a changed comparison or bound without noticing the change |
| Benchmarks with himorime (bench/himorime.yaml) | A pull request that makes a command measurably slower |
How to run each one is in how to build and test.
Contributing
See CONTRIBUTING.md and how to build and test. A GitHub Star also motivates development.
When adding features or fixing bugs, please write unit tests. The README demos are recorded with charmbracelet/vhs from doc/vhs/*.tape (make demo). Bugs and feature requests go to GitHub Issues.
Libraries and tools used
- filesql: the
database/sqldriver that loads and writes back every supported file format, and the dialect translation behind--dialect - prompt: the line editor behind the interactive shell
- atago: the end-to-end test runner, which drives the real
sqlybinary from the plain-YAML specs ine2e/atago/.make test-e2eruns that suite locally, and CI runs it on Linux, macOS, and Windows after installing atago with setup-atago
Acknowledgments
sqly is a memorable project for me because it connected me with two GitHub Sponsors.
Adam Shannon, who works in the payments industry at Moov, inspired sqly's support for financial file formats such as ACH and Fedwire. Shoki Hata, a colleague of mine, has actively used both filesql and sqly; feedback from an actual user improved filesql's performance and led to many bug fixes in sqly.
Thank you both for supporting the project as sponsors, and thanks to everyone who has improved sqly through code, documentation, bug reports, and other contributions.
LICENSE
The sqly project is licensed under the terms of MIT LICENSE.
Contributors ✨
Thanks goes to these wonderful people (emoji key):
CHIKAMATSU Naohiro 💻 📖 |
Wozzardman 💻 |
edsilegxrepo 💻 |
まるこめ 💻 |
Jon Edvardsson 🐛 |
JGStew 🐛 |
Ricardo Seriani 🐛 |
Ephraim Steve Micaiah 🐛 |
Adam Shannon 💵 🤔 |
Shoki Hata 💵 🤔 📓 |
Rafael Baboni Dominiquini 📦 |
|||
|
|
This project follows the all-contributors specification. Contributions of any kind welcome!
Jelajahi proyek terkait
Memuat…