You don't need (to install) any additional Python modules to use sqlite3.

If the database doesn't exist, it will be automatically created usually in the same directory as the script.

On running your script, I get this :-

$ ls *.db
ls: *.db: No such file or directory

$ python test.py

$ ls *.db
mydatabase.db

$ sqlite3 mydatabase.db 
SQLite version 3.7.7 2011-06-25 16:35:41
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> select * from sqlite_master;
table|albums|albums|2|CREATE TABLE albums
             (title text, artist text, release_date text, 
              publisher text, media_type text)
sqlite> 
Answer from Himanshu on Stack Overflow
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ sqlite3.html
sqlite3 โ€” DB-API 2.0 interface for SQLite databases
Both: set detect_types to sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES. Column names take precedence over declared types. The following example illustrates the implicit and explicit approaches:
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-sqlite
Python SQLite - GeeksforGeeks
July 23, 2025 - Python SQLite3 module is used to integrate the SQLite database with Python. It is a standardized Python DBI API 2.0 and provides a straightforward and simple-to-use interface for interacting with SQLite databases.
๐ŸŒ
UCSB Library
carpentry.library.ucsb.edu โ€บ 2021-08-23-ucsb-python-online โ€บ 09-working-with-sql โ€บ index.html
Accessing SQLite Databases Using Python and Pandas โ€“ Summer Data Carpentry: Introduction to Python
August 25, 2021 - An example of using pandas together with sqlite is below: import pandas as pd import sqlite3 # Read sqlite query results into a pandas DataFrame con = sqlite3.connect("data/portal_mammals.sqlite") df = pd.read_sql_query("SELECT * from surveys", con) # Verify that result of SQL query is stored ...
๐ŸŒ
Medium
medium.com โ€บ @drpa โ€บ leveraging-the-power-of-sqlite-with-python-a-practical-tutorial-167fc9dba1c7
Leveraging the Power of SQLite with Python: A Practical Tutorial
April 28, 2023 - Fortunately, SQLite is included in the standard Python library, so you should already have it installed. [check more in the documentation here] To check if SQLite is installed on your system, open up a terminal window and type the following command: ... To create a database, you need to connect to it using the connect() method, which returns a connection object. You can then create a cursor object using the cursor() method, which allows you to execute SQL statements. import sqlite3 # Connect to a database (create if not exists) conn = sqlite3.connect('mydatabase.db') # Create a cursor object to execute SQL statements cur = conn.cursor()
๐ŸŒ
GitHub
gist.github.com โ€บ jtrive84 โ€บ 38faee556a5106c4be9c38635f3ec2e5
Introduction to Python's sqlite3 library and typical usage scenarios. ยท GitHub
============================= Table ... : TICKER TEXT| COMPANY NAME TEXT| ============================= """ import sqlite3 # Create new database `sample.db`. Notice `sample.db` is now # listed in your working director...
๐ŸŒ
W3Schools
w3schools.com โ€บ Python โ€บ ref_module_sqlite3.asp
Python sqlite3 Module
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Training ... import sqlite3 conn = sqlite3.connect(':memory:') cursor = conn.cursor() cursor.execute('CREATE TABLE users (name TEXT, age INTEGER)') cursor.execute("INSERT INTO users VALUES ('Tobias', 28)") conn.commit() cursor.execute('SELECT * FROM users') result = cursor.fetchone() print(f'User: {result[0]}, Age: {result[1]}') Try it Yourself ยป
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ work-with-sqlite-in-python-handbook
How to Work with SQLite in Python โ€“ A Handbook for Beginners
October 2, 2024 - For example, if we want to update a student's age, the SQL command would look like this: UPDATE Students SET age = 21 WHERE name = 'Jane Doe'; Now, letโ€™s write Python code to update a specific student's age in our Students table. import sqlite3 ...
Find elsewhere
Top answer
1 of 4
7

You don't need (to install) any additional Python modules to use sqlite3.

If the database doesn't exist, it will be automatically created usually in the same directory as the script.

On running your script, I get this :-

$ ls *.db
ls: *.db: No such file or directory

$ python test.py

$ ls *.db
mydatabase.db

$ sqlite3 mydatabase.db 
SQLite version 3.7.7 2011-06-25 16:35:41
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> select * from sqlite_master;
table|albums|albums|2|CREATE TABLE albums
             (title text, artist text, release_date text, 
              publisher text, media_type text)
sqlite> 
2 of 4
3

Sqlite3 is the version commonly used with Python. If you are running Windows, you need to download sqlite download from official page. If you are using Ubuntu or Debian based system then it comes pre-installed.

Now coming to python, sqlite3 is the package name, it comes included with python, if you don't find it, then install it with the command apt-get install python-sqlite on Ubuntu system.

Considering you are using Ubuntu system, simply type sqlite3 test.db to create database name test.db.

As for your program:

import sqlite3 

conn = sqlite3.connect("test.db") # connect to test.db 
cursor = conn.cursor() # get a cursor to the sqlite database 
# cursor is the object here, you can use any name

# create a table
cursor.execute("""CREATE TABLE albums
                  (title text, artist text, release_date text, 
                   publisher text, media_type text)""")
# cursor.execute is used to execute any command to sqlite

Few more function I would like to introduce is data = cursor.fetchone() to fetch one row, data = cursor.fetchall() to fetch many rows at once and store in tuple data.

๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ how-to-use-the-sqlite3-module-in-python-3
How To Use the sqlite3 Module in Python 3 | DigitalOcean
June 3, 2020 - In the same way that Python files should be closed when we are done working with them, Connection and Cursor objects should also be closed when they are no longer needed. We can use a with statement to help us automatically close Connection and Cursor objects: from contextlib import closing with closing(sqlite3.connect("aquarium.db")) as connection: with closing(connection.cursor()) as cursor: rows = cursor.execute("SELECT 1").fetchall() print(rows)
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Sqlite3, connection, and general concepts - Python Help - Discussions on Python.org
December 22, 2023 - Assuming code as follows: import sqlite3 def get_price(item_code): with sqlite3.connect("/items.db") as conn: result = conn.execute( "SELECT price WHERE item_code=:item_code", dict(item_code=item_code) ) return result.fetchone() When I call ...
๐ŸŒ
Real Python
realpython.com โ€บ ref โ€บ stdlib โ€บ sqlite3
sqlite3 | Python Standard Library โ€“ Real Python
This module allows you to effortlessly create, manage, and query SQLite databases from Python code. ... >>> import sqlite3 >>> with sqlite3.connect(":memory:") as connection: ... cursor = connection.cursor() ... cursor.execute( ... "CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)" ... ) ... cursor.execute( ... "INSERT INTO users (name) VALUES ('Alice')" ... ) ... connection.commit() ... Connects to SQLite databases stored in files or in-memory ... >>> import sqlite3 >>> connection = sqlite3.connect("example.db") >>> cursor = connection.cursor() >>> cursor.execute( ...
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ sqlite โ€บ sqlite_python.htm
SQLite - Python
You do not need to install this module separately because it is shipped by default along with Python version 2.5.x onwards. To use sqlite3 module, you must first create a connection object that represents the database and then optionally you can create a cursor object, which will help you in executing all the SQL statements.
๐ŸŒ
SQLite Tutorial
sqlitetutorial.net โ€บ home โ€บ sqlite python
SQLite Python
October 26, 2024 - This tutorial series guides you step-by-step on how to work with the SQLite database using Python sqlite3 module.
๐ŸŒ
Remusao
remusao.github.io โ€บ posts โ€บ few-tips-sqlite-perf.html
Getting the most out of SQLite3 with Python
To avoid having to deal manually with rollback or commit, you can simply use the connection object as a context manager. In the following example we create a table, and insert by mistake duplicated values: import sqlite3 connection = sqlite3.connect(':memory:') with connection: connection.execute( ...
๐ŸŒ
SQLite
sqlite.org โ€บ docs.html
SQLite Documentation
About SQLite โ†’ A high-level overview of what SQLite is and why you might be interested in using it ยท Appropriate Uses For SQLite โ†’ This document describes situations where SQLite is an appropriate database engine to use versus situations where a client/server database engine might be a ...
๐ŸŒ
IONOS
ionos.com โ€บ digital guide โ€บ websites โ€บ web development โ€บ sqlite3 python
How to use SQLite3 with Python - IONOS
July 26, 2023 - cursor.execute("INSERT INTO example VALUES (1, alice, 20)") cursor.execute("INSERT INTO example VALUES (2, 'bob', 30)") cursor.execute("INSERT INTO example VALUES (3, 'eve', 40)")python ยท Using the code above you will have added three entries ...
๐ŸŒ
Data Carpentry
datacarpentry.github.io โ€บ python-ecology-lesson โ€บ instructor โ€บ 09-working-with-sql.html
Data Analysis and Visualization in Python for Ecologists: Accessing SQLite Databases Using Python and Pandas
May 18, 2023 - An example of using pandas together with sqlite is below: import pandas as pd import sqlite3 # Read sqlite query results into a pandas DataFrame con = sqlite3.connect("data/portal_mammals.sqlite") df = pd.read_sql_query("SELECT * from surveys", con) # Verify that result of SQL query is stored ...
๐ŸŒ
SQLite Tutorial
sqlitetutorial.net โ€บ home โ€บ sqlite python โ€บ sqlite python: creating tables
SQLite Python: Creating New Tables Example
October 26, 2024 - import sqlite3 database = '<your_database>' create_table = '<create_table_statement>' try: with sqlite3.connect(database) as conn: cursor = conn.cursor() cursor.execute(create_table) conn.commit() except sqlite3.OperationalError as e: print(e)Code ...
๐ŸŒ
GitHub
github.com โ€บ codewithlennylen โ€บ Python-SQLite-Tutorials
GitHub - codewithlennylen/Python-SQLite-Tutorials: This is a simple Tutorial that will show you guys how to use SQLITE3 in python.Hope you will enjoy. ยท GitHub
This is a simple Tutorial that will show you guys how to use SQLITE3 in python.Hope you will enjoy. - codewithlennylen/Python-SQLite-Tutorials
Starred by 36 users
Forked by 12 users
Languages ย  Python