psycopg (v3)

3.3.3 · active · verified Tue Mar 24

psycopg v3 — the successor to psycopg2. Completely rewritten. Install is 'psycopg' (no number), import is 'import psycopg'. Supports both sync and native async (AsyncConnection). Current version: 3.3.3 (Mar 2026). NOT backward compatible with psycopg2 — several behavior changes. For new projects use psycopg over psycopg2. Django 4.2+ supports psycopg v3.

Warnings

Install

Imports

Quickstart

Minimal psycopg v3 sync connection with dict row factory.

# pip install psycopg
import psycopg
from psycopg.rows import dict_row

# Sync usage
with psycopg.connect(
    'postgresql://user:pass@localhost/mydb',
    row_factory=dict_row
) as conn:
    with conn.cursor() as cur:
        cur.execute(
            'SELECT id, name FROM users WHERE active = %s',
            (True,)
        )
        for row in cur.fetchall():
            print(row['name'])  # dict access
    conn.commit()

view raw JSON →