NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
PyPI · #1490 most downloaded on PyPI
Typing stubs for psycopg2
Last release 23 days ago
11 Sep 2026
Release timing varies
gaps range from 1 weeks to 4 months
Nearly every release is documented
notes for 59 of the last 60 stable releases
Nothing withdrawn
no release was ever pulled
5 years old
66 releases · first in 2021
One column per quarter.
* Update to 2.9.13
* Replace NoReturn with Never
NoReturn with Never (#16079)Avoid class-scope name collisions in stubs
Avoid class-scope name collisions in stubs (#15994)
Class members such as list, type, cursor, Model, and datetime shadow the builtins, classes, or modules referenced by nearby annotations. ty then resolves those annotations to Unknown, which can hide invalid calls in APIs including docker, sqlite3, psycopg2, Markdown, and requests.
Qualify shadowed builtins and use private aliases for colliding imports and classes. This removes 15 stdlib and 120 third-party collision diagnostics under ty 0.0.58, restores the affected public types, and fixes four existing psycopg2 type assertions.
Upgrade black to 26.5.0
Upgrade black to 26.5.0 (#15801)
[psycopg2] Annotate some connection argument and return types
[psycopg2] Annotate some connection argument and return types (#15704)
Import some items from typing instead of typing_extensions
Import some items from typing instead of typing_extensions (#15711)
Part of #13782
[psycopg2] Bump to 2.9.12
[psycopg2] Bump to 2.9.12 (#15658)
Use dashes instead of underscores for METADATA.toml field names
Use dashes instead of underscores for METADATA.toml field names (#15614)
Add missing __slots__ to third-party packages
Add missing slots to third-party packages (#15454)
[psycopg2] Update to 2.9.11
[psycopg2] Update to 2.9.11 (#14864)
Add @disjoint_base decorator to the third-party stubs
Add @disjoint_base decorator to the third-party stubs (#14716)
Fix dunder-method positional-only parameter discrepancies in third-party stubs
psycopg2: Add types to RealDictCursor.execute
psycopg2: Add types to RealDictCursor.execute (#14427)
Replace Incomplete | None = None in third party stubs
Replace Incomplete | None = None in third party stubs (#14063)
Fix various argument of extension modules
Fix various argument of extension modules (#13651)
METH_O flag.*args, **kwargs arguments that are using the
METH_NOARGS flag in C.[psycopg2] Fix file argument types
[psycopg2] Fix file argument types (#13418)
[psycopg2] Bump to 2.9.10 (#12835) Mark all error codes as Final
[psycopg2] Bump to 2.9.10 (#12835)
Mark all error codes as Final
Forbid extremely long line lengths in non-autogenerated stubs
Forbid extremely long line lengths in non-autogenerated stubs (#12537)
Co-authored-by: Alex Waygood Alex.Waygood@Gmail.com
Remove remaining bare Incompletes
Remove remaining bare Incompletes (#11768)
Enable Y065
Use PEP 570 syntax in third party stubs
Use PEP 570 syntax in third party stubs (#11554)
psycopg2: make Range generic (#11435) And some other small fixes
psycopg2: make Range generic (#11435)
And some other small fixes
issue-11282: psycopg2 ReplicationConnection.cursor() return type
issue-11282: psycopg2 ReplicationConnection.cursor() return type (#11298)
Co-authored-by: Jelle Zijlstra jelle.zijlstra@gmail.com
psycopg2: Add ReplicationCursor.consume_stream
psycopg2: Add ReplicationCursor.consume_stream (#11283)
Update typing_extensions imports in third-party stubs
psycopg2: improve cursor_factory params
Use ConvertibleToInt/ConvertibleToFloat in many third-party stubs
Use ConvertibleToInt/ConvertibleToFloat in many third-party stubs (#11022)
Note: this may make the latest version of certain stubs packages incompatible with older versions of mypy and pyright.
psycopg2: fix range annotations
psycopg2: fix range annotations (#11071)
Third-party stubs: remove unused type: ignores
Third-party stubs: remove unused type: ignores (#11063)
psycopg2: Accept Composable for cursor.mogrify
psycopg2: Accept Composable for cursor.mogrify (#11028)
Signed-off-by: Anders Kaseorg andersk@mit.edu
psycopg2: Fix missing Protocol base class in file protocols
psycopg2: Fix missing Protocol base class in file protocols (#10943)
This is an error I introduced in #10630 because I didn't know protocols need to be explicitly inherited from in other protocol subclasses.
The added test shows the change. Basically these protocols were unusable.
Complete psycopg2
Complete psycopg2 (#10760)
Fix psycopg2.sql.SQL.join annotation
Fix psycopg2.sql.SQL.join annotation (#10716)
psycopg2: Add missing modules, add annotations
psycopg2: Add missing modules, add annotations (#10630)
Add an upstream_repository field to METADATA.toml
Add an upstream_repository field to METADATA.toml (#10487)
Closes: #10478
Add partial_stub metadata field
Add partial_stub metadata field (#10157)
Add default values for third-party stubs beginning with 'P'
Add default values for third-party stubs beginning with 'P' (#9957)
Improve many __(a)exit__ annotations
Improve many __(a)exit__ annotations (#9696)
Remove unused type: ignore comments
Remove unused type: ignore comments (#9801)
Stubtest settings: change ignore_missing_stub default to false
Stubtest settings: change ignore_missing_stub default to false (#9779)
If you're reading about this commit from an autogenerated changelog entry, this should have no user-visible impact on how the stubs are interpreted by a type checker; it's just an internal change to how typeshed's tests work.
Use typing_extensions.Self instead of _typeshed.Self
Use typing_extensions.Self instead of _typeshed.Self (#9702)
Add a few more hooks. These are all very fast, and I've found them useful in other projects:
Improve pre-commit config (#9563)
trailing-whitespace: fixes trailing whitespacerequirements-txt-fixer: alphabetises items in requirements.txt filesend-of-file-fixer: makes sure every file ends with a single newline charactermixed-line-ending: Makes sure Windows users don't accidentally introduce CRLF line endings into a file that uses LF line endingscheck-yaml: loads YAML files to validate syntaxcheck-toml: loads TOML files to validate syntaxcheck-merge-conflict: detects merge-conflict strings in files and blocks them from accidentally being committedcheck-case-conflict: checks for files with names that would conflict on a case-insensitive filesystem like MacOS HFS+ or Windows FAT; blocks them from being committed.black language target-version to Python 3.10, synching the setting here with the changes that were made to our pyproject.toml file in #7538Replace Any with Incomplete in many places
Replace Any with Incomplete in many places (#9558)
Annotate known magic-method return types
Annotate known magic-method return types (#9131)
psycopg2: __nonzero__ was removed
psycopg2: nonzero was removed (#8863)
Fixes #8862
Improve return type for psycopg2 connect function
Improve return type for psycopg2 connect function (#8567)
When a connection_factory argument is provided to psycopg2's connect function, the function's return type now matches that of the factory output class. However, if cursor_factory is set and has a non-None value and/or connection_factory is not set or is None, the return type is simply connection, as before.
Additional return types for psycopg2 connections
Additional return types for psycopg2 connections (#8528)
DB connection and cursor methods that deal with dict-style results now indicate the expected return types as implemented.
DB connection and cursor methods that deal with namedtuple results now indicate the expected return types as implemented.
As required by flake8, the Iterator referenced in psycopg2's extras module has been switched to the collections.abc.Iterator[T] variant.
The previous return type of Self is wrong; cursor's __iter__ method returns an Iterator.
The previous attempt to fix the return type of cursor's (and subclasses) __iter__ method was misguided; they should indeed return Self. It's the __next__ methods that had to be updated to return the correct record/row instance type.
Provides full method signatures for the cursor methods of the DictConnection, RealDictConnection and NamedTupleConnection types. Notably this includes a default value for cursor_factory in each case, while preserving the option to override the parameter manually.
The return types of the fetch* and __next__ methods of DictCursor, RealDictCursor and NamedTupleCursor are incompatible with the base cursor class's corresponding methods' return types. However, this does accurately reflect reality, so ignore the mypy errors in those cases.
As required by flake8, the Callable referenced in psycopg2's extras module has been switched to the Callable variant.
Several members in the DictCursorBase type definition were entirely unnecessary, so they have been removed. In addition, adds a type to the size param of the cursor's fetchmany method.
Enhanced type hinting for psycopg2 stubs
Enhanced type hinting for psycopg2 stubs (#8500)
Third-party stubs: enforce CamelCase for type alias names
Third-party stubs: enforce CamelCase for type alias names (#8256)
Co-authored-by: Jelle Zijlstra jelle.zijlstra@gmail.com
Extend annotations for psycopg2.sql
Extend annotations for psycopg2.sql (#8263)
Fixes an entry from #7928 along with a number of other improvements.
psycopg2: stub improvements (#7964)
Fixes an entry from #7928 along with a number of other improvements.
I went off the C code: https://github.com/psycopg/psycopg2/blob/master/psycopg/connection_type.c
psycopg2: Fix the return type of Composable.as_string
psycopg2: Fix the return type of Composable.as_string (#7984)
Signed-off-by: Zixuan James Li 359101898@qq.com
Annotations for psycopg2.ConnectionInfo
Annotations for psycopg2.ConnectionInfo (#7834)
These annotations come from the documentation here:
https://www.psycopg.org/docs/extensions.html#psycopg2.extensions.ConnectionInfo If there was doubt, I referred to the libpq documentation cited by psycopg2's docs.
I wasn't completely sure about dsn_parameters. Psycopg2's docs list it
as an dict, and the example suggests it's a dict[str, str] at that.
From psycopg2's source I found
https://github.com/psycopg/psycopg2/blob/1d3a89a0bba621dc1cc9b32db6d241bd2da85ad1/psycopg/conninfo_type.c#L183-L206
which is implemented here:
https://github.com/psycopg/psycopg2/blob/1d3a89a0bba621dc1cc9b32db6d241bd2da85ad1/psycopg/utils.c#L251-L279
I'm no expert in CPython's API, but this looks to me like it's building
a dict[str, str].
Additionally, the libpq docs
https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PQCONNINFO https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PQCONNDEFAULTS
show that the underlying data just consists of strings.
Additionally, I'm pretty sure from this chunk of source
https://github.com/psycopg/psycopg2/blob/1d3a89a0bba621dc1cc9b32db6d241bd2da85ad1/psycopg/conninfo_type.c#L581-L598
That ConnectionInfo.__init__ takes one positional-only argument, which
must be a psycopg2.connection. But I don't think users are intended to
be constructing this type, so I've not added that annotation.
Annotate connection.info and related attributes
Make ConnectionInfo attributes properties
According to https://github.com/psycopg/psycopg2/blob/1d3a89a0bba621dc1cc9b32db6d241bd2da85ad1/psycopg/conninfo_type.c#L534-L563
according to https://github.com/psycopg/psycopg2/blob/8ef195f2ff187454cc709d7857235676bb4176ee/psycopg/connection_type.c#L1244
T | NoneMove cursor class to top of file so it can be used as base class
Annotate Error and Diagnostics (#7671)
Move cursor class to top of file so it can be used as base class
Use TypeAlias for type aliases where possible, part II
Use TypeAlias for type aliases where possible, part II (#7667)
Use TypeAlias where possible for type aliases
Use TypeAlias where possible for type aliases (#7630)
Fixes the return type of psycopg2.cursor.fetchone() to match the psycopg2 code:
psycopg2: correct return type (#7607)
Fixes the return type of psycopg2.cursor.fetchone() to match the psycopg2 code:
https://github.com/psycopg/psycopg2/blob/1d3a89a0bba621dc1cc9b32db6d241bd2da85ad1/psycopg/cursor_type.c#L647-L651 https://github.com/psycopg/psycopg2/blob/1d3a89a0bba621dc1cc9b32db6d241bd2da85ad1/psycopg/cursor_type.c#L748-L786
It also matches the psycopg2 documentation as well as the DB-API
psycopg2: Accept Composable in place of query string
psycopg2: Accept Composable in place of query string (#7494)
https://www.psycopg.org/docs/sql.html#psycopg2.sql.Composable “Composable objects can be passed directly to execute(), executemany(), copy_expert() in place of the query string.”
Signed-off-by: Anders Kaseorg andersk@mit.edu
psycopg2: Annotate cursor execute* and dunder methods
psycopg2: Annotate cursor execute* and dunder methods (#7460)
Correct several positional-only differences in third-party stubs
Correct several positional-only differences in third-party stubs (#7352)
Nothing published for this version
Your coding agent can read these notes before it upgrades. Set up the MCP server →