3

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 settings. I am not looking to deploy to Heroku, just connect locally to this db. Where can I get started?

2 Answers 2

10

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
import psycopg2

DATABASE_URL = os.environ['DATABASE_URL']

conn = psycopg2.connect(DATABASE_URL, sslmode='require')
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.