Psycopg

The modern PostgreSQL adapter for Python, with native async and pipeline support

Library
PyPI
v3.3.6
2,512 stars
LGPL-3.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
80 /100 Excellent
Development Activity 92
Maintenance 52
Community 76
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
83 /100 Excellent
Architecture 85
Code Quality 88
Innovation 82
Learning Curve 75

Psycopg 3 is a complete rewrite of the classic psycopg2 PostgreSQL driver, built around asyncio-native connections and cursors, a C-optimized libpq binding, and strict static typing. It ships as a small family of packages (the pure-Python core, an optional Cython speedup module, and a separate connection-pool package) so applications can pull in exactly the runtime they need.

It is the driver of choice for modern async Python web stacks (FastAPI, Django async views, aiohttp) that need first-class PostgreSQL support without falling back to thread pools, while still supporting fully synchronous usage for traditional codebases.

What You Get

  • Synchronous and native asyncio connection/cursor classes sharing one API surface
  • libpq pipeline mode support for batching multiple queries over one round trip
  • An optional C/Cython extension (psycopg_c) for CPU-bound adaptation hot paths
  • A separate psycopg_pool package with sync and async connection pools
  • Server-side (named) cursors, COPY support, and typed row factories (dict, namedtuple, dataclass)
  • Full type adaptation system mapping PostgreSQL types (including arrays, ranges, JSON) to Python objects

Common Use Cases

  • Powering async web frameworks (FastAPI, Starlette, async Django) that talk to PostgreSQL without blocking the event loop
  • High-throughput services that need pipeline mode to cut round-trip latency on batched writes
  • Migrating psycopg2 codebases to a maintained, actively developed driver with modern typing
  • Applications needing precise control over server-side cursors and COPY for bulk data transfer

Under The Hood

Architecture: The repository is organized as three cooperating packages — psycopg/psycopg (pure-Python core defining Connection/AsyncConnection, Cursor/AsyncCursor, and the adaptation layer in _transformer.py/_adapters_map.py), psycopg_c (a Cython-compiled libpq binding for performance), and psycopg_pool (kept as a separately-released package so pooling can iterate on its own cadence). Connections communicate with PostgreSQL via generator-based state machines (generators.py, waiting.py) that let the same code drive both blocking sockets and asyncio event loops, which is how sync and async cursors share nearly identical implementations. Tech Stack: Python 3.9+, Cython/C for the optional binary extension, libpq as the underlying client library, pytest for testing, mypy --strict for type-checking across all three sub-packages. Code Quality: The tests/ directory contains 70+ test modules covering connections, cursors (sync/async/server-side/raw), COPY, pipelines, transactions, type adaptation, DNS/SRV resolution, and CockroachDB compatibility (tests/crdb/), with mirrored _async variants generated from shared fixtures to keep sync/async behavior in lockstep; mypy strict = true is enforced project-wide via pre-commit hooks. API Design: The public API deliberately follows PEP 249 (DB-API 2.0) conventions extended with async with/async for support, row factories for typed results, and context-manager-based transactions, so developers already familiar with psycopg2 or other DBAPI drivers have very little new surface to learn.

Used by 35 apps in this directory

Svelte
32%
GPL 3.0

Mathesar

Databases

5,158

Spreadsheet-like interface for your PostgreSQL database — self-hosted, no SQL required, native Postgres access control.

View details
70
Repo Health
80
Technical
68
Dependency
Built with
Svelte 32%
TypeScript 27%
Python 21%
Updated 1 weeks ago
Python
45%
GPL 3.0

MaxKB

AI Development · Knowledge Management

23,022

Build enterprise-grade AI agents with RAG, workflows & multi-modal support

View details
92
Repo Health
68
Technical
66
Dependency
Built with
Python 45%
Vue 37%
TypeScript 17%
Updated 1 weeks ago
Python
95%
MIT

MemPalace

AI Agents · AI Development · AI Memory

59,720

Local-first AI memory with verbatim storage, pluggable backends, and 96.6% retrieval recall on LongMemEval — no API key required.

View details
86
Repo Health
84
Technical
73
Dependency
Built with
Python 95%
Updated 1 weeks ago
Python
66%
Other

Morphik

AI Development · Databases · Search

3,717

Morphik is an AI-native ingestion and retrieval engine that lets developers store, search, and reason over visually rich documents — scanned PDFs, manuals, slides, and video — without duct-taping together OCR, an embedding model, and a vector database.

View details
64
Repo Health
71
Technical
67
Dependency
Built with
Python 66%
TypeScript 23%
Updated 1 weeks ago
Python
66%
Other

Morphik

AI Development · Databases · Search

3,717

Morphik is an AI-native ingestion and retrieval engine that lets developers store, search, and reason over visually rich documents — scanned PDFs, manuals, slides, and video — without duct-taping together OCR, an embedding model, and a vector database.

View details
64
Repo Health
71
Technical
67
Dependency
Built with
Python 66%
TypeScript 23%
Updated 1 weeks ago
Python
66%
Other

Morphik

AI Development · Databases · Search

3,717

Morphik is an AI-native ingestion and retrieval engine that lets developers store, search, and reason over visually rich documents — scanned PDFs, manuals, slides, and video — without duct-taping together OCR, an embedding model, and a vector database.

View details
64
Repo Health
71
Technical
67
Dependency
Built with
Python 66%
TypeScript 23%
Updated 1 weeks ago
Python
38%
Other

Open WebUI

AI Agents · AI Assistants

156,607

The extensible, privacy-first AI platform that runs Ollama, OpenAI, and any LLM backend behind a polished, feature-packed web interface.

View details
92
Repo Health
75
Technical
66
Dependency
Built with
Python 38%
Svelte 35%
JavaScript 19%
Updated 6 days ago
TypeScript
54%
Other

OpenReplay

Analytics

13,042

Self-hosted session replay and product analytics suite that lets you see exactly what users do on your web app — without sending data to third parties.

View details
91
Repo Health
77
Technical
66
Dependency
Built with
TypeScript 54%
Go 13%
Updated 1 weeks ago
Python
63%
GPL 3.0

Paperless-ngx

Bookmarks Archiving

47,038

Turn your paper pile into a searchable digital archive with OCR, AI classification, and automated workflows — all running on your own server.

View details
91
Repo Health
88
Technical
67
Dependency
Built with
Python 63%
TypeScript 28%
Updated 6 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers