import psycopg dbh = psycopg.connect('dbname=dbname user=username') print "Connection successful." cur = dbh.cursor() cur.execute("SELECT * FROM myTable") rows = cur.fetchall() for row in rows: print row dbh.close()