You should use the psycopg module to connect to a postgres db from python. Some code samples:
import psycopg2
def connect_db():
try:
conn = psycopg2.connect("dbname='rastertest' user='admin' host='localhost' password='password'")
conn.set_session(autocommit=True) #if you want your updates to take effect without being in a transaction and requiring a commit, for a beginner, I would set this to True
return conn
except:
print "I am unable to connect to the database"
return None
def get_raster(raster_id,conn):
query= "SELECT ST_AsText(geom) from raster_table where id={}".format(raster_id)
conn.cursor().execute(query)
res = cur.fetchall()
return res[0][0]
Maybe the text representation of the raster is something you can use. Alternatively, take a look here http://postgis.net/docs/RT_reference.html to see if any of the functions return what you want for your numpy array and replace the query in get_raster accordingly. (Possibly this http://postgis.net/docs/RT_ST_DumpValues.html)