connect([dbname], [host], [port], [opt], [tty], [user], [passwd])
Name of connected database (string/None).
Name of the server host (string/None).
Port used by the database server (integer/-1).
Options for the server (string/None).
File or tty for optional debug output from backend (string/None).
PostgreSQL user (string/None).
Password for user (string/None).
This method opens a connection to a specified database on a given PostgreSQL server. You can use keywords here, as described in the Python tutorial. The names of the keywords are the name of the parameters given in the syntax line. For a precise description of the parameters, please refer to the PostgreSQL user manual.
import pg con1 = pg.connect('testdb', 'myhost', 5432, None, None, 'bob', None) con2 = pg.connect(dbname='testdb', host='localhost', user='bob')