pip install psycopg2 psycopg2-binary
#!/usr/bin/python
import psycopg2
conn = psycopg2.connect(database="test", user="postgres", password="postgres", host="10.200.22.110", port="5432")
print "Opened database successfully"
cur = conn.cursor()
cur.execute("SELECT id, name from test")
rows = cur.fetchall()
for row in rows:
print "ID = ", row[0]
print "NAME = ", row[1], "
"
print "Operation done successfully";
conn.close()