Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

sql.sqlite.driver

import sql.sqlite.driver

sql lifts part of this module out to its own top level; each name below is shown with the path that reaches it. Anything still spelled sql.sqlite.driver.* needs import sql.sqlite.driver.

Opening SQLite databases: reading a connection string, choosing the open flags, and putting a new connection into a sane state.

Constants

MEMORY

sql.sqlite.MEMORY = ':memory:'

The path that means a private database held in memory, which is discarded when the connection closes.

OPEN_READONLY

sql.sqlite.driver.OPEN_READONLY = 1

OPEN_READWRITE

sql.sqlite.driver.OPEN_READWRITE = 2

OPEN_CREATE

sql.sqlite.driver.OPEN_CREATE = 4

OPEN_URI

sql.sqlite.driver.OPEN_URI = 64

OPEN_MEMORY

sql.sqlite.driver.OPEN_MEMORY = 128

OPEN_NOMUTEX

sql.sqlite.driver.OPEN_NOMUTEX = 32768

OPEN_FULLMUTEX

sql.sqlite.driver.OPEN_FULLMUTEX = 65536

OPEN_SHAREDCACHE

sql.sqlite.driver.OPEN_SHAREDCACHE = 131072

OPEN_PRIVATECACHE

sql.sqlite.driver.OPEN_PRIVATECACHE = 262144

DEFAULT_BUSY_TIMEOUT

sql.sqlite.DEFAULT_BUSY_TIMEOUT = 5000

How long a statement waits for another writer by default.

SQLite’s own default is not to wait at all, which turns any contention into an immediate error. Five seconds is long enough to ride out the short bursts that make up most contention and short enough that a genuine deadlock still surfaces.

MAX_PARAMETERS

sql.sqlite.MAX_PARAMETERS = 32766

Most parameters one statement can bind, which is SQLite’s own limit.

Classes

SqliteDriver

class sql.sqlite.SqliteDriver < Driver

Opens SQLite databases.

SqliteDriver.name()

sql.sqlite.SqliteDriver.name()

SqliteDriver.schemes()

sql.sqlite.SqliteDriver.schemes()

SqliteDriver.capabilities()

sql.sqlite.SqliteDriver.capabilities() -> dict

What SQLite can do.

Two of these are worth reading twice. concurrent_writers is false: a SQLite database takes one writer at a time whatever the journal mode, and a pool over it serialises writes rather than parallelising them. json is false because SQLite has JSON functions but no JSON type, so a list or dictionary is stored as text and comes back as text unless the column says otherwise.

Returns dict

SqliteDriver.parse_dsn()

sql.sqlite.SqliteDriver.parse_dsn(dsn) -> dict

Reads a connection string, or passes an options dictionary through with its defaults filled in.

These all name the same database:

./app.db
sqlite:app.db
sqlite://./app.db
sqlite:///absolute/path/app.db

and these all mean a private in-memory database:

:memory:
sqlite::memory:
sqlite://:memory:

A file: URI is handed to SQLite’s own URI handling, which is how the options SQLite spells itself are reached:

file:app.db?mode=ro&cache=shared

Anything after ? on a non-URI form is read as this adapter’s own options instead. The recognised keys are mode (ro, rw, rwc or memory), busy_timeout in milliseconds, foreign_keys, journal_mode and cache (shared or private).

Parameters

  • dsn (string|dict)

Returns dict

Raises ConnectionError if the string names no database.

SqliteDriver.connect()

sql.sqlite.SqliteDriver.connect(options: dict) -> SqliteConnection

Opens the database and puts it into the state the options ask for.

Parameters

  • options (dict) — From parse_dsn().

Returns SqliteConnection


2026, Richard Ore and Zuri contributors