Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import the "connection" class from psycopg2?

I want to import specifically the connection class from psycopg2 because I want to specify that the argument to one of my functions is indeed a valid psycopg2 connection.

But I am having trouble locating exactly where it is stored. The doc page is here but I can't seem to find any reference to where it is defined, and poking around in the source code has left me more confused.

So far I have tried:

from psycopg2 import connection
from psycopg2.extensions import connection
from psycopg2.extras import connection
from psycopg2.sql import connection

But none of them are valid references

like image 535
wfgeo Avatar asked Sep 14 '25 19:09

wfgeo


1 Answers

You can find it here:

from psycopg2._psycopg import connection

But this is an internal object, so you shouldn't do that. It is meant that connection objects are created via psycopg2.connect() factory method.

like image 168
Ivan Vinogradov Avatar answered Sep 16 '25 08:09

Ivan Vinogradov