The recommended way to connect to postgres is via the client psycopg2. Install it with pip install psycopg2. Follow the example to connect with a postgres database. Remember that you need to setup your DATABASE_URL to point either to a local machine or the remote elephantsql instance.

import os
import psycopg2
import urlparse

urlparse.uses_netloc.append("postgres")
url = urlparse.urlparse(os.environ["DATABASE_URL"])

conn = psycopg2.connect(database=url.path[1:],
  user=url.username,
  password=url.password,
  host=url.hostname,
  port=url.port
)

Python resources