Search notes:

PEP 249 - Python Database API Specification v2.0

PEP 249 specifies common usage patterns for Python packages that allow to connect to databases.

DBAPI

DBAPI is a commonly seen abbreviation that stands for Python Database API Specification.

Interfaces and objects

Module interface

apilevel Evaluates to 1.0 or 2.0
connect() Returns a Connection object
paramstyle qmark: ? | numeric: :1 | named: :name | format : name=%2 | pyformat: %(name)s
threadsafety 03

Connection object

close()
commit()
rollback()
cursor() Returns a new Cursor object

Cursor object

arraysize R/W: Number of rows fetched with fetchmany()
callproc() Calls a stored procedure. If the procedure produces a resultset, it must be iterated over using fetch()
connection Optional, v2
description A sequence of 7-item (of which only the first two are mandatory) sequences describing one result column.
execute() Prepare and execute a statement. An optional second argument specifies the values that will be bound to variables in the statement (sequence or mapping).
executemany() See also arraysize
fetchall()
fetchmany() See also arraysize
fetchone() Returns one record as a tuple (see these SQLite examples)
lastrowid Returns the last inserted rowid.
next() Optional, v2
nextset() Skip to the next available set. (Optional as not all databases support multiple result sets)
messages Optional, v2
rowcount
rownumber Optional, v2
scroll() Optional, v2
setinputsizes(s)
setoutputsize(s[, col])
__iter__ Optional, v2: Make cursors compatible with the iterable protocol.

Exception hierarchy

StandardError
   Warning
   Error
      InterfaceError
      DatabaseError
         DataError
         OperationalError
         IntegrityError
         InternalError
         ProgrammingError
         NotSupportedError

See also

The standard library sqlite3
A small list of other interesting PEPs
The Python libraries

Links

https://peps.python.org/pep-0249/

Index