Updated Sep 21, 2026

Utilities

Run SQL on a CSV file with csvsql

SQL on one CSV. The table name is the file stem.

Agent

overview

What csvkit does

You have a CSV, and the next node needs a filtered or aggregated table. Connect the file to input and set --query. The wrapper runs csvsql and tees stdout to the output file. The table name is the filename without its extension. A script that writes output.txt must query FROM output.

-d sets the delimiter. -e sets encoding. --no-header-row is a boolean; leave it disconnected when the file has a header. Do not connect unused booleans. Hive will pass true or false as leftover argv and csvsql will fail.

csvkit is in-process SQL on one CSV. Use duckdb when you need Parquet, JSON, or a join across files. A query that names the wrong table fails the node. Check the input filename before you write FROM.

source github.com/wireservice/csvkit

use cases

Where csvkit fits

Filter rows

Set --query to SELECT ... FROM stem WHERE .... The output file is the result CSV.

Aggregate

Use GROUP BY in --query. The table name is still the file stem.

Change the delimiter

Set -d when the file is not comma-separated.

Headerless CSV

Connect --no-header-row only when the file has no header. Leave it off otherwise.

reference

csvkit inputs and flags

5 inputs
NameTypeFlagDescription
inputFILE·Input CSV file to query.
querySTRING--querySQL query. Table name is the filename without its extension.
delimiterSTRING-dField delimiter. Default comma.
encodingSTRING-eCharacter encoding. Default UTF-8.

Showing key inputs. csvkit exposes 5 inputs in total.

Full flag reference (5 inputs)
NameTypeFlagDescription
delimiterSTRING-dField delimiter character (default comma)
encodingSTRING-eCharacter encoding of input CSV (default UTF-8)
no-headerBOOLEAN--no-header-rowSet if the CSV has no header row
querySTRING--querySQL query to execute. The table name is the filename without its extension.
inputFILE·Input CSV file to query

example

Run csvkit

csvkit · command
# csvkit csvsql; last argv is the Hive output filecsvsql --query "SELECT name, n FROM data WHERE n > 1" data.csv
sample output
name,nb,2.0

guidance

Choosing csvkit

Use csvkit when the input is one CSV and the query is SQL. Use duckdb when you need Parquet, JSON, or more than one file.

duckdb

In-process SQL on CSV, JSON, and Parquet. Use it when csvsql is too narrow.

wget

Downloads a CSV. It does not query it.

jq

Filters JSON, not CSV.

faq

csvkit questions

The input filename without its extension. output.txt is queried as FROM output.

Run csvkit yourself

A two-row CSV feeds csvsql WHERE n > 1. The result below is from a completed run.

Facts on this page come from the live Trickest tool library.