import psycopgdbh = psycopg.connect('dbname=dbname user=username')print "Connection successful."cur = dbh.cursor()cur.execute("SELECT * FROM myTable")cur.fetchone() print "Obtained %d rows" % cur.rowcountdbh.close()