skillfed

types-psycopg2

Typing stubs for psycopg2

types-psycopg2 v2.9.21.20260724 8.6M downloads/30d#1,605 on PyPI37
Permissive license Apache-2.0 Active released

What it is and what it does

types-psycopg2 is a type stub package that adds static type information to psycopg2, the widely-used PostgreSQL adapter for Python. It allows type checkers like mypy and pyright to understand the types and signatures of psycopg2's API, catching type errors at development time rather than runtime. The stubs are maintained as part of the typeshed project and aim to provide accurate annotations for psycopg2 version 2.9.12.

This package has no runtime dependencies and installs as a pure Python wheel. It is intended to be used alongside psycopg2 itself during development and type-checking workflows. The stubs have been tested with mypy 2.3.0 and pyright 1.1.411, and the package is actively maintained with recent updates.

Use it for:

  • Enable mypy or pyright to type-check code that imports and uses psycopg2 for database connections.
  • Catch type errors in psycopg2 method calls and result handling before running tests.
  • Provide IDE autocomplete and inline type hints when working with psycopg2 in a type-aware editor.
  • Validate that database query results and cursor operations match expected types in a CI/CD pipeline.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides type hints for psycopg2, enabling static type checkers like mypy and pyright to validate code that uses the PostgreSQL adapter.

Yes, if you use psycopg2 and run static type checking. The package is lightweight, has no dependencies, and is actively maintained. Install it alongside psycopg2 to enable type checking in your development workflow. Not necessary if you do not use a type checker or do not use psycopg2.

Install

types-psycopg2 on PyPI

pip

pip install types-psycopg2

uv

uv add types-psycopg2

poetry

poetry add types-psycopg2

Installing types-psycopg2

Before you install

Low install friction with no runtime dependencies. Actively maintained as part of typeshed; last commit 2026-08-14 and release 21 days ago.

License in practice

Apache-2.0 is permissive; you may use, modify, and distribute this package freely in most contexts without restriction.

Quickstart

pip install types-psycopg2

import psycopg2
conn = psycopg2.connect("dbname=test user=postgres")

Requires Python >= 3.10. Type checking requires a compatible type checker (mypy 2.3.0 or pyright 1.1.411 or later).

Verify before relying

  • Coverage of psycopg2 API surface beyond 2.9.12 (e.g., newer versions or extensions).
  • Whether stubs are kept in sync with psycopg2 releases after 2.9.12.

Package facts

License Apache-2.0 (permissive)
Python support supports the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance actively maintained — 21 days since the last release
Last repo commit
First released
Downloads 8,579,609/month — #1,605 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: types_psycopg2-2.9.21.20260724-py3-none-any.whl

Programming Language :: Python :: 3Typing :: Stubs Only

Tags

psycopg2 type hintspsycopg2 type stubspostgresql adapter typingmypy psycopg2 supportpyright psycopg2 annotationstype checking postgresqlpsycopg2 static analysis
type-stubspostgresql

More Database packages