scipy-stubs provides comprehensive type annotations for the SciPy library, enabling static type checking for SciPy-based projects and enhancing IDE features like autocompletion and error detection. It offers full coverage of the public SciPy API with precise shape-typing and dtype-typing without any runtime overhead. The current version is 1.17.1.3, designed to be compatible with SciPy 1.17.1 and supporting Python 3.11-3.14. Releases are independent but target specific SciPy versions.
pip install scipy-stubsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates using `scipy.optimize.minimize` with type annotations for inputs and outputs. After installing `scipy-stubs`, your type checker (like MyPy or Pyright) and IDE will automatically provide type-checking and autocompletion for SciPy functions, even without explicit type annotations in your own code. The stubs ensure that the types for `x0`, `res`, and function arguments are correctly understood.
Avoid treating `_RichResult` as a `dict` at the type level. Access attributes directly or convert to a dict explicitly if dictionary-like behavior is truly needed.
Always install `scipy-stubs` and `scipy` versions that are explicitly compatible. Check the `scipy-stubs` release notes or PyPI page for the exact `SciPy`, Python, and NumPy version requirements. Consider using `pip install scipy-stubs[scipy]` to ensure both are installed correctly.
Understand that `scipy-stubs` is a development-time dependency. Do not add `import scipy_stubs` statements to your production code. Ensure your type checker is configured to find installed stub packages.
Update `scipy-stubs` to the latest compatible version with your `SciPy` installation to benefit from the most accurate type hints, especially for `scipy.sparse` operations.
Utilize `from __future__ import annotations` in your modules. Keep `scipy-stubs` and `scipy` updated to versions that support runtime subscriptability for generic types if you intend to use them.