liveBook · Manning

Sqlite3

As explained in A Pythonic Adventure: From Python basics to a working web app

The sqlite3 module is Python's standard-library interface for working with SQLite databases.

Use sqlite3 to replace a fragile file of coffee orders with an SQLite database that can handle multiple people writing orders. section 12.0

A small database workflow looks like this:

  • Import sqlite3 and connect to orders.db. section 12.0
  • Create a cursor so SQL commands can run. section 12.0
  • Create an orders table with name, drink, flavor, and topping columns. section 12.0
  • Insert each order with placeholders, then commit the change. section 12.0
  • Select saved rows and display them in a Flask template. section 12.0

Coffee-shop orders

A Flask app saves each customer's name, drink, flavor, and topping in orders.db, then lists the stored orders in an HTML table. section 12.0

. . .
import sqlite3                                                          #1
. . .
con = sqlite3.connect("orders.db")                                      #2
cur = con.cursor()
cur.execute(
    "CREATE TABLE IF NOT EXISTS orders(name, drink, flavor, topping);") #3
 
app = Flask(name)
. . .

Inspect the compact connection, cursor, and CREATE TABLE setup. section 12.0

How A Pythonic Adventure: From Python basics to a working web app covers it

How deep it goes
Demonstrates connections, cursors, table creation, inserts, commits, selects, and template display without deeper cursor details.
Examples
Uses a coffee-shop orders table and a Flask page that lists drinks, flavors, toppings, and customer names.
What it assumes
Teaches database connections, cursors, tables, rows, and basic SQL through a concrete application.
What you can do after
Build a Flask order application that stores and retrieves records with SQLite.
How it connects
Links sqlite3 with SQLite, SQL, databases, cursors, Flask, and HTML templates.

Also explained in

Compare how 3 books explain sqlite3 →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of A Pythonic Adventure: From Python basics to a working web app. The section links point to the parts of the book it draws on.