Home

Awesome

<h1 align="center">scipy-stubs</h1> <p align="center"> Precise type hints for <i>all</i> of <a href="https://github.com/scipy/scipy">SciPy</a>. </p> <p align="center"> <a href="https://pypi.org/project/scipy-stubs/"> <img alt="scipy-stubs - PyPI" src="https://img.shields.io/pypi/v/scipy-stubs?style=flat&color=olive" /> </a> <a href="https://anaconda.org/conda-forge/scipy-stubs"> <img alt="scipy-stubs - conda-forge" src="https://anaconda.org/conda-forge/scipy-stubs/badges/version.svg" /> </a> <a href="https://github.com/jorenham/scipy-stubs"> <img alt="scipy-stubs - Python Versions" src="https://img.shields.io/pypi/pyversions/scipy-stubs?style=flat" /> </a> <a href="https://github.com/jorenham/scipy-stubs"> <img alt="scipy-stubs - license" src="https://img.shields.io/github/license/jorenham/scipy-stubs?style=flat" /> </a> </p> <p align="center"> <a href="https://github.com/jorenham/scipy-stubs/actions?query=workflow%3ACI"> <img alt="scipy-stubs - CI" src="https://github.com/jorenham/scipy-stubs/workflows/CI/badge.svg" /> </a> <a href="https://github.com/pre-commit/pre-commit"> <img alt="scipy-stubs - pre-commit" src="https://img.shields.io/badge/pre--commit-enabled-teal?logo=pre-commit" /> </a> <a href="https://github.com/KotlinIsland/basedmypy"> <img alt="scipy-stubs - basedmypy" src="https://img.shields.io/badge/basedmypy-checked-fd9002" /> </a> <a href="https://detachhead.github.io/basedpyright"> <img alt="scipy-stubs - basedpyright" src="https://img.shields.io/badge/basedpyright-checked-42b983" /> </a> <a href="https://github.com/astral-sh/ruff"> <img alt="scipy-stubs - ruff" src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" /> </a> </p>

Highlights

<!-- NOTE: SciPy permalinks to the following `#installation` anchor; don't modify it! -->

Installation

The source code is currently hosted on GitHub at github.com/jorenham/scipy-stubs.

Binary distributions are available at the Python Package Index (PyPI) and on conda-forge.

Using pip (PyPI)

To install from the PyPI, run:

pip install scipy-stubs

In case you haven't installed scipy yet, both can be installed with:

pip install scipy-stubs[scipy]

Using conda (conda-forge)

To install using Conda from the conda-forge channel, run:

conda install conda-forge::scipy-stubs

It's also possible to install both scipy and scipy-stubs together through the bundled scipy-typed package:

conda install conda-forge::scipy-typed

Packages overview

<table> <tr> <th rowspan="2" colspan="2"></th> <th colspan="2">Python packages</th> </tr> <tr> <th><code>scipy-stubs</code></th> <th><code>scipy</code> + <code>scipy-stubs</code></td> </tr> <tr> <th>PyPI</th> <th align="right"><code>pip install {}</code></th> <td><code>scipy-stubs</code></td> <td><code>scipy-stubs[scipy]</code></td> </tr> <tr> <th>conda-forge</th> <th align="right"><code>conda install conda-forge::{}</code></th> <td><code>scipy-stubs</code></td> <td><code>scipy-typed</code></td> </tr> </table>

Versioning and requirements

The versioning scheme of scipy-stubs includes the compatible scipy version as {scipy_version}.{stubs_version}. Even though scipy-stubs doesn't enforce an upper bound on the scipy version, later scipy versions aren't guaranteed to be fully compatible.

The supported range of numpy versions are specified in SPEC 0, which scipy-stubs aims to follow as close as feasible.

Currently, scipy-stubs has one required dependency: optype. This is essential for scipy-stubs to work properly, as it relies heavily on it for annotating (shaped) array-likes, scalar-likes, shape-typing in general, and much more. At the moment, scipy-stubs requires the latest version optype.

The exact version requirements are specified in the pyproject.toml.

Supported static type-checkers

  1. basedpyright (recommended)
  2. basedmypy
  3. pyright
  4. mypy (not recommended, see erictraut/mypy_issues)

For validation and testing, scipy-stubs primarily uses basedmypy (a mypy fork) and basedpyright (a pyright fork). They are in generally stricter than mypy and pyright, so you can assume compatibility with mypy and pyright as well. But if you find that this isn't the case, then don't hesitate to open an issue or submit a pull request.

scipy coverage

The entire public API of scipy is fully annotated and verifiably valid. For the most part, this can also be said about scipy's private API and other internal machinery.

Untyped

A small portion of the stubs uses the Untyped type (an alias of Any) as a "placeholder" or "to-do" annotation. In those cases static type-checkers won't do any type-checking, and won't bother you with errors or warnings, so you probably won't even notice it. The current goal of scipy-stubs is to replace all Untyped annotations with more meaningful ones.

At the moment, out of the 21 scipy.* subpackages, the only one that still has (some) Untyped annotations, is scipy.signal. See scipy-stubs#99 for an overview.

Contributing

There are many ways that you can help improve scipy-stubs, for example

AI generated Podcast

Typing in SciPy

https://github.com/user-attachments/assets/adbec640-2329-488b-bda2-d9687c6b1f7b

See also