Overview
pg8000 supports the standard Python DB-API, version 2.0, as documented in PEP-249. The DB-API interface is contained within a class called DBAPI inside the pg8000 module. An additional module, pg8000_dbapi, is available to access this class namespace as a module.
There are therefore two ways to import the DB-API interface of pg8000:
from pg8000 import DBAPI
or
import pg8000_dbapi
Usage of the DB-API is pretty standard compared to other DB-API compatible modules. The following documents unusual or noteworthy points in the DB-API implementation.
connect method
The connect method is used to create a new connection to the database. It supports the same keyword arguments that the pg8000.Connection class supports.
execute method
The execute method of cursor objects takes exactly two arguments, the query string and the argument list or dictionary. Some DB-API implementations permit multiple arguments or keyword arguments to execute, but pg8000 does not.
paramstyle parameter
pg8000 supports any of the parameter styles documented in PEP-249. This currently includes "qmark" (A = ?), "numeric" (A = :1), "named" (A = :a), "format" (A = %s), and "pyformat" (A = %(a)s). The parameter style can be changed by setting the pg8000.DBAPI.paramstyle global parameter.
Support for the "format" and "pyformat" parameter styles is limited to only %s and %(name)s, the styles explicitly documented in PEP-249.
When using the "pyformat" or "named" parameter styles, the argument object supplied to execute must be dict-compatible.
