you can download current stable Psycopg 2.4.6 here or you can use PyPI(Python Package Install) with easy_install psycopg2.
if you download package, you can install it with python setup.py install command. dont forget that you will probably need python-dev and libpq-dev packages.
The pg_config must be available in your path, or alternatively you
must specify its full path in the setup.cfg file.
after installation, you can call it:
import psycopg2
and example code from Postgresql Wiki:
import psycopg2
try:
conn = psycopg2.connect("dbname='template1' user='dbuser' host='localhost'
password='dbpass'")
except:
print "I am unable to connect to the database"
cur = conn.cursor()
cur.execute("""SELECT datname from pg_database""")
rows = cur.fetchall()
print "\nShow me the databases:\n"
for row in rows:
print " ", row[0]
i hope it helps you...