Last modified: Sep 22, 2026

Does Python Come With SQLite

Does Python Come With SQLite?

Yes, Python comes with SQLite included. It is part of the standard library. This means you can start using SQLite databases right away without installing additional packages.

Python includes the sqlite3 module by default. This module provides a simple way to interact with SQLite databases using Python.

In this article, we will explore how to check if SQLite is available, create a database, and perform basic operations.

Check If SQLite Is Available

Before working with SQLite, it's good to verify that the sqlite3 module is available in your Python installation.


import sqlite3
print(sqlite3.version)

This script imports the sqlite3 module and prints its version.


2.6.0

If no error occurs, SQLite is available in your Python environment.

Create a Simple Database

Creating a database with Python and SQLite is straightforward. You do not need to install anything extra.


import sqlite3

# Connect to a new or existing database
conn = sqlite3.connect('example.db')

# Create a cursor object
cursor = conn.cursor()

# Create a table
cursor.execute('''
CREATE TABLE IF NOT EXISTS users (
    id INTEGER PRIMARY KEY,
    name TEXT NOT NULL,
    age INTEGER
)
''')

conn.commit()
conn.close()

This code creates a file called example.db if it does not exist. It also creates a table named users.


No output is shown if successful.

Insert Data Into the Table

Once the table is created, you can insert data into it.


import sqlite3

conn = sqlite3.connect('example.db')
cursor = conn.cursor()

# Insert a new user
cursor.execute('INSERT INTO users (name, age) VALUES (?, ?)', ('Alice', 30))

conn.commit()
conn.close()

This inserts one record into the users table.


No output is shown if successful.

Retrieve Data From the Table

You can fetch data using a SELECT query.


import sqlite3

conn = sqlite3.connect('example.db')
cursor = conn.cursor()

# Fetch all rows
cursor.execute('SELECT * FROM users')
rows = cursor.fetchall()

for row in rows:
    print(row)

conn.close()

This prints all records from the users table.


(1, 'Alice', 30)

Update Existing Records

You can update data using the UPDATE statement.


import sqlite3

conn = sqlite3.connect('example.db')
cursor = conn.cursor()

# Update Alice's age
cursor.execute('UPDATE users SET age = ? WHERE name = ?', (31, 'Alice'))

conn.commit()
conn.close()

This changes Alice's age from 30 to 31.


No output is shown if successful.

Delete Records

To remove data, use the DELETE command.


import sqlite3

conn = sqlite3.connect('example.db')
cursor = conn.cursor()

# Delete Alice
cursor.execute('DELETE FROM users WHERE name = ?', ('Alice',))

conn.commit()
conn.close()

This deletes the record where the name is Alice.


No output is shown if successful.

Why Use SQLite With Python?

  • No separate server setup required.
  • Lightweight and fast.
  • Ideal for small to medium applications.
  • Stores everything in a single file.

These features make SQLite a great choice for learning and prototyping.

Common Issues and Fixes

Sometimes you might see an error like this:


ModuleNotFoundError: No module named 'sqlite3'

This usually means SQLite support was not compiled into your Python build. Reinstalling Python with SQLite enabled can fix this.

Learn More About Python SQLite

Explore advanced topics such as Python SQLite example, create database guide, and install setup guide.

Conclusion

Python does come with SQLite built-in. The sqlite3 module makes it easy to create, read, update, and delete data. Whether you are building a small app or learning databases, SQLite is a solid choice.