We use psycopg2 to connect PostgreSQL. It is the best and most user-friendly Python database adapter. It is both Unicode and Python3 friendly.
Requires installation —
pip install psycopg2
Let`s get started and break the link with PostgreSQL piece by piece.
Step # 1: Connect to PostGreSQL
Step # 2: Declare a cursor
Allows Python code to execute a PostgreSQL command in a database session.
cur code >
Step # 3: Write your SQL query and execute it.
| tr> |
Step # 4: Close the connection