Python stdlib · DB-API 2.0 interface for SQLite · verified against CPython 3.12–3.14

sqlite3 cheat sheet

sqlite3 is Python's built-in, zero-config SQL database — a whole relational engine in one file (or in memory), no server. It implements the DB-API 2.0: connect, get a cursor, execute parameterized SQL, fetch rows. Perfect for local apps, tests, caches, and prototypes. This sheet is current for CPython 3.12–3.14 and flags the modern autocommit transaction control and 3.12/3.13 deprecations.

connect query & params transactions types & funcs backup & CLI gotcha most common

Verified 2026-08-24 against the official docs at docs.python.org/3/library/sqlite3 (CPython 3.14; notes apply to 3.12+). The bundled SQLite library version is sqlite3.sqlite_version. Python 3.12+ only for the autocommit attribute and the python -m sqlite3 shell.

Outline

connectexecute with ? placeholders → fetch. Commit writes (or use with con:). Then types, custom functions, backup, and the built-in shell.

Connect & query

  1. 1 · Connect & cursor
  2. 2 · Execute & parameters
  3. 3 · Fetch & Row

Write & transact

  1. 4 · Insert, update, bulk
  2. 5 · Transactions & autocommit
  3. 6 · Types & converters

Power & ship

  1. 7 · Functions & extensions
  2. 8 · Backup, dump, WAL, CLI
  3. 9 · Gotchas
  4. Worth memorizing

Connect & query

Open a database, run parameterized SQL, read rows back.

1Connect & cursoropen a database
2Execute & parametersnever format SQL by hand
3Fetch & Rowread results

Write & transact

Insert data, control transactions, and map Python types.

4Insert, update, bulkand commit
5Transactions & autocommit3.12+ control
6Types & convertersPython ↔ SQLite

Power & ship

Extend SQL with Python, back up live databases, and use the built-in shell.

7Functions & extensionsPython inside SQL
8Backup, dump, WAL, CLIoperate the DB
!Common gotchasread before shipping

Worth memorizing

connect("app.db") / ":memory:"file or in-RAM database
execute(sql, (a, b))? placeholders; named uses :name + dict
never f-string SQLinjection; params for values only
fetchone / fetchall / iterate cursorstream rows lazily
row_factory = sqlite3.Rowcolumns by name
executemany(sql, seq)fast bulk insert
with con:commit/rollback — but does NOT close
commit() to persistlegacy mode holds until you do
autocommit=False (3.12+)modern transaction control
PRAGMA foreign_keys=ONoff by default, per connection
PRAGMA journal_mode=WALread/write concurrency
con.backup(dst) · python -m sqlite3live backup · built-in shell (3.12+)