psycopg2-binary: PostgreSQL Database Adapter for Python
psycopg2-binary is a PostgreSQL adapter for Python, providing a means to interact with PostgreSQL databases. The current version is 2.9.11, and it follows a regular release cadence with periodic updates and bug fixes.
Warnings
- breaking Using 'psycopg2-binary' in production environments is discouraged due to potential conflicts with system libraries and lack of binary upgradeability.
- deprecated The 'psycopg2.tz' module is deprecated and will be removed in psycopg2 version 2.10.
Install
-
pip install psycopg2-binary
Imports
- connect
from psycopg2 import connect
Quickstart
import psycopg2
# Connect to your postgres DB
conn = psycopg2.connect(dbname='test', user='postgres', password='secret')
# Open a cursor to perform database operations
cur = conn.cursor()
# Execute a query
cur.execute('SELECT * FROM my_data')
# Retrieve query results
records = cur.fetchall()
# Don't forget to close the cursor and connection
cur.close()
conn.close()