SQLite is a small database stored in a local file.
Python includes sqlite3, so you can practice database storage without installing a server.
Use SQLite for learning SQL, small apps, local tools, prototypes, and project data that should survive after the program stops.
A connection opens the database file. SQL statements create tables and query data.
import sqlite3
with sqlite3.connect("tasks.db") as conn:
conn.execute("""
CREATE TABLE IF NOT EXISTS tasks (
id INTEGER PRIMARY KEY,
title TEXT NOT NULL
)
""")
The database file is created if it does not exist.
Use parameter placeholders for values instead of joining strings into SQL.
import sqlite3
with sqlite3.connect(":memory:") as conn:
conn.execute("CREATE TABLE tasks (title TEXT)")
conn.execute("INSERT INTO tasks (title) VALUES (?)", ("Learn SQLite",))
rows = conn.execute("SELECT title FROM tasks").fetchall()
print(rows[0][0])
Learn SQLite
The value is inserted safely through a placeholder and then read back.
0 of 2 checked
Try this next
0 of 3 completed
For basic Python use, no. The sqlite3 module is included with Python.
Yes. It is excellent for local task apps, notes apps, small reports, and learning SQL.
Placeholders keep values separate from SQL syntax, which avoids many quoting mistakes and unsafe query patterns.
Explore 500+ free tutorials across 20+ languages and frameworks.