GUIDES / GETTING STARTED

Python sqlite3: Create a Database and Inspect It Online

Use Python to create a local SQLite file, then inspect it in SQLite Lab. This example uses synthetic data and the standard-library sqlite3 module. Python code runs on your computer, not in the SQL editor.

For a guided sequence with runnable downloads, continue to the four Python SQLite lessons.

Create a small database

Choose a new filename for the example. Use bound parameters for values. Commit the inserts, then close the connection before opening the resulting database in the viewer.

import sqlite3

connection = sqlite3.connect('python-example.sqlite')
try:
    connection.execute('CREATE TABLE notes (id INTEGER PRIMARY KEY, body TEXT)')
    connection.executemany(
        'INSERT INTO notes(body) VALUES (?)',
        [('Learn SQLite',), ('Inspect the database',)],
    )
    connection.commit()
finally:
    connection.close()

Inspect your file

Open python-example.sqlite in the workspace and click notes. You should see two rows. The browser uses a separate copy; changes here do not update the Python source file until you explicitly download and replace it yourself.

Working with live databases

Do not copy only the main database file while a writer is active in WAL mode. Use Python’s Connection.backup method or the source application’s backup feature to obtain a consistent snapshot. SQLite Lab does not import WAL sidecars.

Keep exploring

SQLite syntax reference · Practice with a learning path · Sample datasets

How to Open a .db File in Your Browser

Reference: Official SQLite documentation