Skip to content Skip to sidebar Skip to footer

Connecting Python To A Heroku Postgresql Db?

I am exploring various features of the Python language. I have created a Postgres db on Heroku, am am looking to connect to it. I have the host, database user, port and password se

Solution 1:

From Heroku Postgres doc, with psycopg2 :

To use PostgreSQL as your database in Python applications you will need to use the psycopg2 package.

pip install psycopg2-binary

And use this package to connect to DATABASE_URL in your code.

import os
importpsycopg2DATABASE_URL= os.environ['DATABASE_URL']

conn = psycopg2.connect(DATABASE_URL, sslmode='require')

Solution 2:

I don't know anything about Heroku, but maybe psycopg is what you're looking for?

Post a Comment for "Connecting Python To A Heroku Postgresql Db?"