FROM SQL TO A SMALL APPLICATION

SQLite with Python

Work through four small scripts, each with sample data, expected output and an exercise. They use Python's sqlite3 module and run on your computer. The browser playground runs SQL, not Python.

Before you begin

Use Python 3.12 or newer with the sqlite3 module available. Download a lesson and run it with python3, or python on installations using that command. These examples use temporary in-memory databases.

python3 --version
  1. Connect and query

    Create a small in-memory database and read rows by column name.

  2. Bind values safely

    Use placeholders for values instead of building SQL from user input.

  3. Make changes atomically

    Observe a failed transaction rolling back all of its changes.

  4. Import CSV with validation

    Parse a CSV stream, validate values and insert the batch in one transaction.

Official Python sqlite3 reference · Practice SQL fundamentals · SQLite setup guide