The psycopg module#
Psycopg implements the Python Database DB API 2.0 specification. As such it also exposes the module-level objects required by the specifications.
- psycopg.connect(conninfo='', *, autocommit=False, prepare_threshold=5, row_factory=None, cursor_factory=None, context=None, **kwargs)#
Connect to a database server and return a new
Connectioninstance.- Return type
This is an alias of the class method
Connection.connect: see its documentation for details.If you need an asynchronous connection use
AsyncConnection.connectinstead.
Exceptions
The standard DBAPI exceptions are exposed both by the psycopg module
and by the psycopg.errors module. The latter also exposes more specific
exceptions, mapping to the database error states (see
SQLSTATE exceptions).
Exception|__Warning|__Error|__InterfaceError|__DatabaseError|__DataError|__OperationalError|__IntegrityError|__InternalError|__ProgrammingError|__NotSupportedError
- psycopg.adapters#
The default adapters map establishing how Python and PostgreSQL types are converted into each other.
This map is used as a template when new connections are created, using
psycopg.connect(). Itstypesattribute is aTypesRegistrycontaining information about every PostgreSQL builtin type, useful for adaptation customisation (see Data adaptation configuration):>>> psycopg.adapters.types["int4"] <TypeInfo: int4 (oid: 23, array oid: 1007)>
- Type