Last Updated : 15 Jul, 2025
SQLite is a lightweight, fast and embedded SQL database engine. SQLite is perfect for small to medium-sized applications, prototyping, embedded systems and local data storage in Python applications because it doesn't require a separate server process like other relational database management systems (RDBMS) like MySQL or PostgreSQL.
Features of SQLite:We don't need to install anything additional to get started because Python has built-in support for SQLite through the sqlite3 module. Let's understance each of the features in detail.
ServerlessGenerally, an RDBMS such as MySQL, PostgreSQL, etc., needs a separate server process to operate. The applications that want to access the database server use TCP/IP protocol to send and receive requests and it is called client/server architecture. The diagram below illustrates the working of relational databases:
Working of Relational DatabasesSQLite does not require a server to run. SQLite database read and write directly from the database files stored on disk and applications interact with that SQLite database. It is one of SQLite's biggest advantages is that it is serverless. Here's what that means:
SQLite is self-contained, here's what it means:
Unlike other databases, SQLite requires zero setup:
Example: Connecting to a SQLite Database in Python
Python
import sqlite3
conn = sqlite3.connect('example.db') # Creates a new database file if it doesn’t exist
cursor = conn.cursor()
Transactional
We can also manage transactions explicitly using:
Transaction Control Example:
Python
conn.execute("BEGIN")
# perform database operations
conn.commit() # or conn.rollback() if something fails
Single-Database
SQLite uses a single-file database architecture, meaning:
Benefits of Single-File Storage:
While SQLite is simple to use, it offers several advanced features:
Parameterized QueriesTo prevent SQL injection:
Row Factorycursor.execute("SELECT * FROM users WHERE id = ?", (user_id,))
Fetch rows as dictionaries:
In-Memory Databasesconn.row_factory = sqlite3.Row
For temporary, fast operations:
Using with Statement for Safe Resource Handling:conn = sqlite3.connect(':memory:')
with sqlite3.connect('example.db') as conn:
cursor = conn.cursor()
cursor.execute("SELECT * FROM users")
Explanation:
import sqlite3: imports Python’s built-in SQLite module, which allows interaction with SQLite databases.
sqlite3.connect('example.db'): establishes a connection to a SQLite database file named example.db.
conn.cursor(): creates a cursor object from the connection, which is used to execute SQL queries and fetch results.
To learn more about different types of relation databses, refer to: MySQL, PostgreSQL.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4