SQLite: the database that is just a file, and when to use it
2 min readDeveloper Tools · Tools · Guides
SQLite is a complete SQL database engine that lives in a single file. There is no server to install, no port to open, no user to create: your program opens a file and reads and writes it. It ships inside Python's standard library, on Android and iOS devices, and in countless desktop apps, and its code is in the public domain. For a lot of projects it is the right database, and the usual mistake is reaching for something heavier first.
What it actually is
- A library linked into your application, not a separate process.
- One file holds the whole database: tables, indexes and data.
- Full SQL with transactions, indexes, views, triggers and full-text search.
- ACID transactions, so a crash mid-write does not corrupt the file under normal conditions.
- The sqlite3 command-line shell for inspecting a database by hand.
A minimal example
import sqlite3
con = sqlite3.connect("app.db")
con.execute("PRAGMA journal_mode=WAL")
con.execute("PRAGMA foreign_keys=ON")
con.execute(
"CREATE TABLE IF NOT EXISTS notes (id INTEGER PRIMARY KEY, body TEXT NOT NULL)"
)
con.execute("INSERT INTO notes (body) VALUES (?)", ("hello",))
con.commit()
print(con.execute("SELECT id, body FROM notes").fetchall())Two pragmas matter. WAL mode lets readers keep working while one writer commits, and it persists in the database file. Foreign key enforcement is off by default and has to be switched on for every connection.
When it is the right choice
- Local apps, command-line tools and desktop software.
- Mobile apps, where it is already built in.
- Small and medium websites that are mostly reads, on a single server.
- Development and testing, where you want a database with zero setup.
- Data files you want to query with SQL instead of parsing by hand.
Where it bites
- One writer at a time. Writes are serialized. Many sites never notice, but a write-heavy workload with many concurrent writers will.
- Not for network filesystems. Locking over NFS or SMB is unreliable. Keep the file on local disk.
- Several machines. There is no built-in client-server access or replication. If multiple servers need the same database, use Postgres or MySQL, or a tool built around SQLite replication.
- Loose typing. Columns have type affinity, not strict types, unless you declare the table STRICT in a recent version.
- Backups. Copying the file while it is being written can give you a torn copy. Use the .backup command or VACUUM INTO instead.
Verdict
Start with SQLite unless you have a concrete reason not to: several app servers, heavy concurrent writes, or a need for network access. It is fast, boring and easy to back up, and you can move to Postgres later if the project outgrows it.
Docs: sqlite.org

Written by
Shihab Hossain — Full-Stack Developer
I build thoughtful digital products from Bangladesh — fast web experiences with Next.js, Android apps with Flutter, and the infrastructure behind them.
Work with me