numpy-typing-compat
Static typing compatibility layer for older versions of NumPy
What it is and what it does
numpy-typing-compat is a compatibility layer that lets you write NumPy type annotations that adapt to the installed NumPy version. It provides version-specific boolean constants (like NUMPY_GE_2_1) and type aliases (StringDType, ABCPolyBase, LiteralTrue, LiteralFalse) that static type-checkers can understand, similar to how you'd use sys.version_info for Python version checks. This is particularly useful for library authors who need to support multiple NumPy versions while maintaining accurate type hints.
The package is tightly coupled to NumPy versions—each release targets a specific NumPy minor version range (e.g., 20260602.2.5 targets numpy >=2.4,<2.5). Modern package managers like uv and pixi automatically install the correct version, but pip users must manually ensure alignment. The package is actively maintained and designed as a helper for the optype library, though it can be used directly when you need fine-grained version-aware typing.
Use it for:
- Library authors supporting multiple NumPy versions who need type-checkers to understand version-specific APIs without runtime overhead
- Conditional type annotations for NumPy 2.0+ features like StringDType that weren't available in earlier versions
- Handling NumPy 2.1+ generic type changes (ABCPolyBase) while maintaining backward compatibility with older versions
- Type-safe use of NumPy 2.2+ bool scalar generics (LiteralTrue, LiteralFalse) across version boundaries
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides version-specific type annotations for NumPy code, allowing static type-checkers to understand which NumPy version is installed and apply appropriate type hints accordingly.
Yes, if you are a library author supporting multiple NumPy versions and need static type-checkers to understand version-specific type differences. Use modern package managers (uv, pixi) to avoid manual version management. Not necessary for applications using a single NumPy version or if you rely on optype for higher-level typing utilities.
Install
numpy-typing-compat on PyPI
pip
pip install numpy-typing-compatuv
uv add numpy-typing-compatpoetry
poetry add numpy-typing-compatInstalling numpy-typing-compat
Before you install
Low install friction with a single runtime dependency on numpy. Actively maintained as of 2026-08-14 with recent releases. Requires Python 3.12 or later and is designed to work with modern package managers like uv and pixi that respect version constraints; pip users must manually ensure version compatibility.
License in practice
BSD-3-Clause permissive license allows use in most projects without significant restrictions.
Quickstart
pip install numpy-typing-compat
from numpy_typing_compat import NUMPY_GE_2_1, StringDType
if NUMPY_GE_2_1:
dtype = StringDType()
else:
dtype = None
Requires Python 3.12 or later. The installed version of numpy-typing-compat must match your NumPy version—modern package managers handle this automatically, but pip requires manual version alignment.
Verify before relying
- How well mypy and pyright actually support Literal-based version conditions in practice beyond the documented 'limited support'
- Whether the package is actively used by optype or other production libraries beyond its intended helper role
Package facts
| License | BSD-3-Clause (permissive) |
| Python support | supports the current Python release (>=3.12) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — numpy |
| Maintenance | actively maintained — 73 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 3,920,133/month — #2,452 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: numpy_typing_compat-20260602.2.5-py3-none-any.whl
Keywords: numpy, optype, typing, compatibility
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
scipy-stubsProvides type stubs for the entire SciPy…
permissive · top 5,000 on PyPI
typingProvides type hints and annotations for Python…
permissive · top 5,000 on PyPI
types-shapelyProvides type stubs for the shapely package,…
permissive · top 15,000 on PyPI
typing-aliasesProvides a collection of type aliases for…
permissive · top 15,000 on PyPI
types-coloramaProvides type stubs for colorama, enabling…
permissive · top 5,000 on PyPI
optypeoptype provides single-method protocols and…
permissive · top 5,000 on PyPI
types-cffiProvides type stubs for the cffi package,…
permissive · top 5,000 on PyPI
django-nineProvides version checking utilities for Django,…
copyleft · top 15,000 on PyPI
types-PygmentsProvides type hints for the Pygments syntax…
permissive · top 5,000 on PyPI
types-geopandasProvides type annotations for the geopandas…
permissive · top 15,000 on PyPI