Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Learning Heroku Postgres
  • Table Of Contents Toc
Learning Heroku Postgres

Learning Heroku Postgres

By : Patrick Rafael de Oliveira Espake
4.3 (4)
close
close
Learning Heroku Postgres

Learning Heroku Postgres

4.3 (4)
By: Patrick Rafael de Oliveira Espake

Overview of this book

Learning Heroku Postgres is targeted at developers and database admins. Even if you're new to Heroku Postgres, you'll be able to master both the basic as well as advanced features of Heroku Postgres. Since Heroku Postgres is incredibly user-friendly, no previous experience in computer coding or programming is required.
Table of Contents (12 chapters)
close
close
9
A. Keyword List
11
Index

Connecting with Python


In order to use PostgreSQL as database in your Python applications it is necessary to use the psycopg2 package and add it in the dependency file called requirements.txt. The following is just a code sample to help you understand the concept;

$ pip install psycopg2
$ pip freeze > requirements.txt

Then, use the psycopg2 package to connect the DATABASE_URL variable:

import psycopg2
import urlparse
import os

try:
    urlparse.uses_netloc.append("postgres") 
    connection_params = urlparse.urlparse(os.environ["DATABASE_URL"])
    db_connection = psycopg2.connect(database = connection_params.path[1:], user = connection_params.username, password = connection_params.password, host = connection_params.hostname, port = connection_params.port)
except:
    print "Database connection failed."
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Learning Heroku Postgres
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon