psycopg2-binary: PostgreSQL Database Adapter for Python

2.9.11 · active · verified Sat Mar 28

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

Install

Imports

Quickstart

A basic example demonstrating how to connect to a PostgreSQL database and execute a query using psycopg2.

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()

view raw JSON →