sqlite-utils: pipe JSON or CSV into SQLite, query it in memory, and reshape tables ALTER TABLE cannot
Python CLI utility and library for manipulating SQLite databases
At a glance
- What is it?
- Simon Willison's sqlite-utils is both a command-line tool and a Python library for SQLite files. It infers schemas from JSON and CSV, runs SQL against flat files, and rebuilds tables for changes SQLite cannot make directly. Version 4 raised the Python floor to 3.10.
- Who is it for?
- Use sqlite-utils when data arrives as JSON, CSV or TSV and you want it in a queryable SQLite file within one command, or when a Python script needs terse table creation without hand-written DDL. Look elsewhere if you must stay on Python below 3.10 or need a server database.
- Can I use it commercially?
- Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 12 days ago.
- What is it written in?
- Mainly Python, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 24, 2026, and from our analysis. They are not legal advice.
Star history
- simonw/sqlite-utils2,227 ★ · +48
| Repository | 2026-10-08 | 2026-11-24 |
|---|---|---|
| simonw/sqlite-utils | 2.2k | 2.2k |
48 Stars in the last 47 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
One command turns JSON or CSV into a table with an inferred schema
The headline feature is `insert`: pipe JSON, CSV or TSV into a database file and a table appears with a schema chosen from the data. You do not write a `CREATE TABLE` first.
$ sqlite-utils insert dogs.db dogs dogs.csv --csv
[####################################] 100%The command takes a database path, a table name and a source file, with `--csv` marking the format. A progress bar fills as rows load. JSON works the same way from standard input, and the README shows it against the GitHub releases API:
$ curl https://api.github.com/repos/simonw/sqlite-utils/releases \
| sqlite-utils insert releases.db releases - --pk idThe lone `-` means read standard input, and `--pk id` names the primary key. That pair is what turns a curl response into a keyed table in one line. When you do not pass `--pk`, the README does not say what key the table gets, so set it whenever you plan to upsert or join later.
sqlite-utils memory queries flat files without keeping a database
`sqlite-utils memory` imports CSV or JSON into an in-memory database and runs a SQL query against it in the same command. Nothing is written to disk, which suits one-off questions about a file you will not keep.
$ sqlite-utils memory dogs.csv "select * from t"
[{"id": 1, "age": 4, "name": "Cleo"},
{"id": 2, "age": 2, "name": "Pancakes"}]The imported file is exposed as a table, `t` in this example. Piped data arrives as `stdin`:
$ cat dogs.csv | sqlite-utils memory - "select name, age from stdin"The highlights list says the queries can include joins across files, so two CSVs can be combined without loading either into a persistent database. Because the database lives in memory for the length of the command, a result you want to keep has to be redirected or written out, since the command leaves no table behind.
Output formats: JSON by default, CSV or a table on request
A plain query against a database file prints JSON. The README shows the same query three ways:
$ sqlite-utils dogs.db "select id, name from dogs"
[{"id": 1, "name": "Cleo"},
{"id": 2, "name": "Pancakes"}]
$ sqlite-utils dogs.db "select * from dogs" --csv
id,age,name
1,4,Cleo
2,2,PancakesSwapping `--csv` for `--table` prints an aligned text table with a header rule, which is what you read in a terminal. JSON is the default because the tool is meant to sit in pipelines, where the next program parses it.
One more command is worth knowing: `sqlite-utils tables dogs.db --counts` lists every table with a row count, returning `[{"table": "dogs", "count": 2}]` in the sample. It gives a quick sanity check after an import, before you write any query. If the count is lower than the number of lines in your source file, the import dropped rows or the file held a header you did not expect, and that is the moment to find out, not after a report has been built on the table.
The tool name on the command line is `sqlite-utils`, registered in `pyproject.toml` as a script that points at `sqlite_utils.cli:cli`, so a virtual environment is enough to put it on your path.
Transform rebuilds a table for changes ALTER TABLE does not allow
SQLite's `ALTER TABLE` cannot change a column's type, among other edits. sqlite-utils offers transformations that make those schema changes for you, with the README's own example being a change of column type. The CLI section is titled transforming tables, and the Python API exposes the same operation.
A companion feature extracts columns into a separate table to normalise existing data. If a `species` column repeats the same strings across thousands of rows, extraction moves the values into their own table and replaces the original column with a reference.
The README describes both in a line each and sends you to the CLI documentation for the flags. It does not say how a transform treats existing rows that do not fit the new type, or whether it runs inside a transaction. For a database you cannot afford to damage, run the transform on a copy first and diff the results before touching the original file.
Full-text search is configured from the same tool
A third highlight is SQLite full-text search. You configure it against your database tables and then run search queries against them, ordered by relevance. The package depends on `sqlite-fts4`, listed among the runtime requirements, which is the visible link to that feature.
The point is that FTS setup in raw SQLite takes virtual tables and triggers to keep the index current. Here it is a command on an existing table. The README gives no flags and no query syntax, so the CLI documentation section on configuring full-text search is the reference to follow.
What you get is search inside the database file, with no separate search server, so the index travels with the `.db` file when you copy it to another machine. The limits are those of SQLite's own FTS support and of the tool's configuration options, neither of which the README spells out. If you need typo tolerance or faceting, check the documentation before assuming it exists.
The library mirrors the CLI, and plugins and migrations extend both
In Python, `import sqlite_utils` gives you a `Database` object. A table is reached by indexing it, and rows go in with `insert_all`:
import sqlite_utils
db = sqlite_utils.Database("demo_database.db")
# This line creates a "dogs" table if one does not already exist:
db["dogs"].insert_all([
{"id": 1, "age": 4, "name": "Cleo"},
{"id": 2, "age": 2, "name": "Pancakes"}
], pk="id")The comment in the example is the useful part: the table is created when missing, with no DDL.
Two further features appear in the highlights. Migrations are written as Python migration files and run with `sqlite-utils migrate`. Plugins add custom SQL functions and other features, and the dependency on `pluggy` is the hook system behind them. The README links to documentation for both and describes neither in detail, so what a migration file looks like has to come from the migrations page.
Version 4 requires Python 3.10, and 3.x users get an upgrade guide
The `pyproject.toml` sets `requires-python = ">=3.10"`, with classifiers for 3.10 through 3.14 and a Production/Stable development status. Anyone on an older interpreter cannot install the current line.
The README opens a pointer for people upgrading from sqlite-utils 3.x to the 4.0 upgrade guide. It does not summarise the breaking changes, so read that guide before bumping a pin. The release list shows 4.2.1 and 4.2 both published on 2026-08-13, a few hours apart, and 3.39.1 on 2026-07-26. A 3.x patch release shortly before the 4.2 releases suggests the old line was still being maintained.
Runtime dependencies are `click`, `click-default-group`, `pluggy`, `python-dateutil`, `sqlite-fts4`, `tabulate` and `pip`. Install with `pip install sqlite-utils`, or `brew install sqlite-utils` on macOS. The license is Apache-2.0, the last push was on 2026-10-11, and the author's related projects include Datasette, csvs-to-sqlite, db-to-sqlite and the Dogsheep family.
Editorial conclusion
Use sqlite-utils when data arrives as JSON, CSV or TSV and you want it in a queryable SQLite file within one command, or when a Python script needs terse table creation without hand-written DDL. Look elsewhere if you must stay on Python below 3.10 or need a server database. Before upgrading a 3.x project, read the 4.0 upgrade guide, because the README does not list what changed.
Frequently asked questions
What is sqlite-utils?
sqlite-utils is a Python CLI utility and library for manipulating SQLite databases. It loads JSON, CSV and TSV into tables, runs in-memory SQL queries, configures full-text search and transforms table schemas.
How do I install sqlite-utils?
Run pip install sqlite-utils, or brew install sqlite-utils on macOS with Homebrew. Version 4.2.1 requires Python 3.10 or newer.
Does sqlite-utils need a table schema before importing CSV?
No. Piping JSON, CSV or TSV into a new database file automatically creates a table with the appropriate schema. Setting --pk id names the primary key.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/simonw-sqlite-utils)Star history chart for your README
[](https://hysenlabs.com/projects/simonw-sqlite-utils)Was this useful?