The psycopg2 Package
Last updated
Was this helpful?
Last updated
Was this helpful?
The psycopg2
("psycho pee gee") package provides a way for Python to interface with databases.
Psycopg is the most popular PostgreSQL adapter for the Python programming language. At its core it fully implements the Python DB API 2.0 specifications. Several extensions allow access to many of the features offered by PostgreSQL. -
Reference:
Run a psycopg2
application "in development" using a database server on your local machine, and/or "in production" using a remote database server hosted by a provider like Heroku. If you run it in development, you should be able to connect via localhost, whereas if you run it in production, you should be able to connect using the production server's credentials. The professor recommends using or some other GUI interface to your PostgreSQL databases, local or remote.
As a prerequisite: install PostgreSQL on your local machine. If you are on a Mac, use Homebrew: brew install postgresql
and follow the post-installation instructions. Make sure you can connect to your local PostgreSQL installation via a GUI or command-line interface. If attempting to connect from the command-line, try running psql
or perhaps psql -U your_username
, depending on the name of your computer's user and method of PostgreSQL installation. Note the username and password you are using to connect.
After demonstrating your ability to connect to a local PostgreSQL installation, install the Python package:
To setup this example, gain access to an existing PostgreSQL database, and observe its connection credentials.