types-psycopg2
Typing stubs for psycopg2
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-psycopg2uv
uv add types-psycopg2poetry
poetry add types-psycopg2Installing 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
Tags
More Database packages
psycopg2-binary is a PostgreSQL database…
copyleft · top 1,000 on PyPI
redisPython client library for connecting to and…
permissive · top 1,000 on PyPI
ydbYDB Python SDK is the official client library…
permissive · top 1,000 on PyPI
snowflake-connector-pythonConnects Python applications to Snowflake data…
permissive · top 1,000 on PyPI
sqlparsesqlparse tokenizes SQL text into a tree of…
permissive · top 1,000 on PyPI
dbt-adaptersProvides base adapter protocols and shared…
permissive · top 1,000 on PyPI
types-pyflakesProvides type stubs for the pyflakes static…
permissive · top 15,000 on PyPI
types-mypy-extensionsProvides type stubs for mypy-extensions,…
permissive · top 15,000 on PyPI
types-paramikoProvides type hints for paramiko, enabling…
permissive · top 1,000 on PyPI
types-docutilsProvides type hints for the docutils library,…
permissive · top 5,000 on PyPI
types-fpdf2Provides type stubs for the fpdf2 PDF…
permissive · top 15,000 on PyPI
optypeoptype provides single-method protocols and…
permissive · top 5,000 on PyPI
types-httplib2Provides type stubs for the httplib2 HTTP…
permissive · top 5,000 on PyPI
types-PyMySQLProvides type stubs for PyMySQL to enable…
permissive · top 5,000 on PyPI
types-dockerProvides type hints for the docker package,…
permissive · top 5,000 on PyPI
types-jmespathProvides type annotations for the jmespath…
permissive · top 5,000 on PyPI