The connection class — Psycopg 2.9.3 documentation
www.psycopg.org › docs › connectionThe connection class¶ class connection¶ Handles the connection to a PostgreSQL database instance. It encapsulates a database session. Connections are created using the factory function connect(). Connections are thread safe and can be shared among many threads. See Thread and process safety for details. Connections can be used as context ...
Using psycopg2 with PostgreSQL - PostgreSQL wiki
wiki.postgresql.org › wiki › Using_psycopg2_withJan 30, 2015 · #!/usr/bin/python import psycopg2 import sys import pprint def main (): conn_string = "host='localhost' dbname='my_database' user='postgres' password='secret'" # print the connection string we will use to connect print "Connecting to database -> %s " % (conn_string) # get a connection, if a connect cannot be made an exception will be raised here conn = psycopg2. connect (conn_string) # conn ...