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, row_factory=None, **kwargs)

Connect to a database server and return a new Connection instance.

Return type

Connection[Any]

This is an alias of the class method Connection.connect: see its documentation for details.

If you need an asynchronous connection use AsyncConnection.connect instead.

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 global, default adapters map establishing how Python and PostgreSQL types are converted into each other. This map is used as template when new connections are created, using psycopg.connect().

Type

AdaptersMap