psycopg2
Popular PostgreSQL adapter for Python with full database access and query execution.
Databases, ORMs and clients PyPI LGPL with exceptions
Used in agent projects
143
1.1% of 12,697 public repos built with AI coding agents
Rank in databases, orms and clients
#7 of 30
by use in those projects
Downloads
50.7M
PyPI, last 7 days, psycopg2-binary
GitHub stars
3,656
last push Oct 1, 2026
How psycopg2 is used
psycopg2 is a dependency in 143 of the 12,697 public GitHub projects set up for AI coding agents that we scanned (1.1%), #7 of 30 in databases, orms and clients. The most used alternative there is Prisma. Projects that use it most often also use python-dotenv (77.6%), SQLAlchemy (63.6%), Pydantic (58.7%).
Often used with psycopg2
| python-dotenv | 77.6% of psycopg2 projects · 11.9× more than average |
|---|---|
| SQLAlchemy | 63.6% of psycopg2 projects · 32.3× more than average |
| Pydantic | 58.7% of psycopg2 projects · 11.5× more than average |
| FastAPI | 57.3% of psycopg2 projects · 13.6× more than average |
| Uvicorn | 57.3% of psycopg2 projects · 13.4× more than average |
| Requests | 53.8% of psycopg2 projects · 10.1× more than average |
| NumPy | 39.9% of psycopg2 projects · 10.4× more than average |
| pytest | 37.8% of psycopg2 projects · 14.5× more than average |
By coding agent
| Cursor | 1.8% of projects set up for it |
|---|---|
| GitHub Copilot | 1.4% of projects set up for it |
| Claude Code | 1.3% of projects set up for it |
| Devin Desktop | 2.2% of projects set up for it |
Share of public repos configured for each agent that list psycopg2 as a dependency.
Install
| Package | pip install psycopg2-binary |
|---|---|
| Main stacks | Python (139), Next.js (3), React Native / Expo (1) |
| Example projects | Josh-XT/AGiXT, imbue-bit/AlphaGPT, MDalamin5/End-to-End-Agentic-Ai-Automation-Lab, XargonWan/Synthetic_Heart, NihadMemmedli/quorvex_ai |
Alternatives to psycopg2
| Tool | Used in agent projects | Downloads / wk | GitHub stars | License |
|---|---|---|---|---|
| Prisma npm Modern ORM with intuitive schema, migrations, and type-safe database queries. |
381 (3.0%) | 19M | 23 | Apache-2.0 |
| pg npm PostgreSQL client for Node.js with pure JavaScript and libpq API compatibility. |
372 (2.9%) | 63.4M | 13.2K | MIT |
| Drizzle ORM npm TypeScript ORM for SQL databases with type safety and zero-runtime overhead. |
323 (2.5%) | 27.2M | 36K | Apache-2.0 |
| Drizzle Kit npm CLI migration tool for Drizzle ORM that auto-generates SQL migrations intelligently. |
309 (2.4%) | 22.3M | 36K | MIT |
| SQLAlchemy pypi Python SQL toolkit and object-relational mapper for database abstraction. |
250 (2.0%) | 85.7M | 12.2K | — |
| better-sqlite3 npm Fastest and simplest SQLite library for Node.js with synchronous API. |
162 (1.3%) | 11.3M | 7,513 | MIT |
| Mongoose npm MongoDB object modeling library providing schema validation and query building. |
142 (1.1%) | 6.6M | 27.5K | MIT |
| Neon Serverless Driver npm PostgreSQL driver optimized for serverless environments from Neon. |
126 (1.0%) | 4.5M | 552 | MIT |