Gem

sqlite-utils

A Python library and CLI for building and querying SQLite databases from files or pipelines.

Would you recommend sqlite-utils?

No votes yet. Tried it? Be the first to say.

One vote per person. No account needed.

Overview

sqlite-utils imports CSV, TSV and JSON into SQLite and can infer a table schema from incoming records. It can run SQL over temporary in-memory tables or create a persistent database file. The same project exposes a Python API for insertion, transformation and schema tasks.

Instead of
One-off CSV loaders and scratch database scripts.
Reach for it when
Reach for it when an export or fixture would be easier to inspect with SQL.

Key features

  • In-memory SQL

    The memory command loads files into a temporary database and queries them in one invocation.

  • Persistent file import

    The insert command loads records into a SQLite file and can infer an initial table schema.

  • Several output formats

    Query results can be emitted as JSON, CSV or a terminal table.

  • Python API

    Python programs can use the library to perform database and table operations directly.

In depth

Install

The PyPI package includes both the CLI and the Python library. The documented examples below assume a local CSV named dogs.csv. The first query uses a temporary database, and the next command creates or updates a database file named dogs.db. Project README

bash
pip install sqlite-utils
sqlite-utils memory dogs.csv "select * from t"
sqlite-utils insert dogs.db dogs dogs.csv --csv

How it works

The memory command gives an input file a table name and runs ordinary SQLite SQL against it. It can also load multiple files for a join. Use a persistent file when a second script or person needs the same imported rows, or when you want to inspect table counts and run more queries later. Output options let a single workflow emit terminal tables for people and JSON or CSV for another tool. CLI documentation

Good to know

  • Inference helps with exploration. Fixtures that depend on exact types, keys or constraints benefit from an explicit schema.
  • An in-memory import consumes memory for the temporary database. Persistent imports are available when you need to reuse the data. CLI documentation · Release notes

Strengths and watch-outs

Strengths

  • Turns a file into a queryable table in one command
  • Bridges shell scripts and Python
  • Supports disposable and persistent workflows

Watch out for

  • Inferred types may need correction
  • In-memory workloads are bounded by available memory
  • The query dialect is SQLite SQL

Try it in a few minutes

Terminal
pip install sqlite-utils
sqlite-utils memory dogs.csv "select * from t"
sqlite-utils insert dogs.db dogs dogs.csv --csv

Alternatives

sqlite3

SQLite's own shell provides SQL and import commands with fewer format-handling conveniences.

DuckDB CLI

It can query data files directly and is designed around analytical workloads and its own database engine.

Related tools

Other tools that share topics with sqlite-utils.

pgcli

pgcli.com
Gem

pgcli is an interactive PostgreSQL shell with SQL completion and syntax highlighting.

Instead of Interactive psql sessions and desktop database browsers.

llm (CLI)

llm.datasette.io
Gem

Use LLMs from the command line and pipe anything into them.

Instead of Copy-pasting terminal output into a chat window

jq

jqlang.org
Gem

Slice, filter and reshape JSON on the command line.

Instead of Ad-hoc Python or Node scripts, and grep/sed on JSON (which breaks as soon as the formatting changes)