PyDocs

Data Persistence

sqlite3

The sqlite3 extension module provides a DB-API 2.0 (PEP 249) compliant
interface to the SQLite library, and requires SQLite 3.15.2 or newer.

To use the module, start by creating a database Connection object:

    import sqlite3
    cx = sqlite3.connect("test.db")  # test.db will be created or opened

The special path name ":memory:" can be provided to connect to a transient
in-memory database:

    cx = sqlite3.connect(":memory:")  # connect to a database in RAM

Once a connection has been established, create a Cursor object and call
its execute() method to perform SQL queries:

    cu = cx.cursor()

    # create a table
    cu.execute("create table lang(name, first_appeared)")

    # insert values into a table
    cu.execute("insert into lang values (?, ?)", ("C", 1972))

    # execute a query and iterate over the result
    for row in cu.execute("select * from lang"):
        print(row)

    cx.close()

The sqlite3 module is written by Gerhard Häring <gh@ghaering.de>.
Symbols in sqlite3

a

apilevel
String constant stating the supported DB-API level.

b

Blob
A Blob instance is a file-like object that can read and write data in an SQLite BLOB.

c

complete_statement
Checks if a string contains a complete SQL statement.
connect
Open a connection to the SQLite database file 'database'.
Connection
SQLite database connection object.
Cursor
SQLite database cursor class.

d

DatabaseError
Exception raised for errors that are related to the database.
DataError
Exception raised for errors caused by problems with the processed data, like numeric values out of range, and strings which are too long.

e

enable_callback_tracebacks
Enable or disable callback functions throwing errors to stderr.
Error
The base class of the other exceptions in this module.

i

IntegrityError
Exception raised when the relational integrity of the database is affected, e.g.
InterfaceError
Exception raised for misuse of the low-level SQLite C API.
InternalError
Exception raised when SQLite encounters an internal error.

l

LEGACY_TRANSACTION_CONTROL
Set autocommit to this constant to select old style (pre-Python 3.12) transaction control behaviour.

n

NotSupportedError
Exception raised in case a method or database API is not supported by the underlying SQLite library.

o

OperationalError
Exception raised for errors that are related to the database’s operation, and not necessarily under the control of the programmer.

p

paramstyle
String constant stating the type of parameter marker formatting expected by the sqlite3 module.
PARSE_COLNAMES
Pass this flag value to the detect_types parameter of connect() to look up a converter function by using the type name, parsed from the query column name, as the converter dictionary key.
PARSE_DECLTYPES
Pass this flag value to the detect_types parameter of connect() to look up a converter function using the declared types for each column.
PrepareProtocol
PEP 246 style object adaption protocol type.
ProgrammingError
Exception raised for sqlite3 API programming errors, for example supplying the wrong number of bindings to a query, or trying to operate on a closed Connection.

r

register_adapter
Register a function to adapt Python objects to SQLite values.
register_converter
Register a function to convert SQLite values to Python objects.
Row
A Row instance serves as a highly optimized row_factory for Connection objects.

s

SQLITE_DBCONFIG_DEFENSIVE
These constants are used for the Connection.setconfig() and getconfig() methods.
SQLITE_DBCONFIG_DQS_DDL
These constants are used for the Connection.setconfig() and getconfig() methods.
SQLITE_DBCONFIG_DQS_DML
These constants are used for the Connection.setconfig() and getconfig() methods.
SQLITE_DBCONFIG_ENABLE_FKEY
These constants are used for the Connection.setconfig() and getconfig() methods.
SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER
These constants are used for the Connection.setconfig() and getconfig() methods.
SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION
These constants are used for the Connection.setconfig() and getconfig() methods.
SQLITE_DBCONFIG_ENABLE_QPSG
These constants are used for the Connection.setconfig() and getconfig() methods.
SQLITE_DBCONFIG_ENABLE_TRIGGER
These constants are used for the Connection.setconfig() and getconfig() methods.
SQLITE_DBCONFIG_ENABLE_VIEW
These constants are used for the Connection.setconfig() and getconfig() methods.
SQLITE_DBCONFIG_LEGACY_ALTER_TABLE
These constants are used for the Connection.setconfig() and getconfig() methods.
SQLITE_DBCONFIG_LEGACY_FILE_FORMAT
These constants are used for the Connection.setconfig() and getconfig() methods.
SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE
These constants are used for the Connection.setconfig() and getconfig() methods.
SQLITE_DBCONFIG_RESET_DATABASE
These constants are used for the Connection.setconfig() and getconfig() methods.
SQLITE_DBCONFIG_TRIGGER_EQP
These constants are used for the Connection.setconfig() and getconfig() methods.
SQLITE_DBCONFIG_TRUSTED_SCHEMA
These constants are used for the Connection.setconfig() and getconfig() methods.
SQLITE_DBCONFIG_WRITABLE_SCHEMA
These constants are used for the Connection.setconfig() and getconfig() methods.
SQLITE_DENY
Flags that should be returned by the authorizer_callback callable passed to Connection.set_authorizer(), to indicate whether:
SQLITE_IGNORE
Flags that should be returned by the authorizer_callback callable passed to Connection.set_authorizer(), to indicate whether:
SQLITE_KEYWORDS
A tuple containing all SQLite keywords.
SQLITE_OK
Flags that should be returned by the authorizer_callback callable passed to Connection.set_authorizer(), to indicate whether:
sqlite_version
Version number of the runtime SQLite library as a string.
sqlite_version_info
Version number of the runtime SQLite library as a tuple of integers.

t

threadsafety
Integer constant required by the DB-API 2.0, stating the level of thread safety the sqlite3 module supports.

w

Warning
This exception is not currently raised by the sqlite3 module, but may be raised by applications using sqlite3, for example if a user-defined function truncates data while inserting.