Skip to main content

Precise type-hints for all of SciPy

Project description

scipy-stubs

Precise type hints for all of SciPy.

scipy-stubs - PyPI scipy-stubs - conda-forge scipy-stubs - Python Versions scipy-stubs - license

scipy-stubs - CI scipy-stubs - pre-commit scipy-stubs - basedmypy scipy-stubs - basedpyright scipy-stubs - ruff


Highlights

  • Works out-of-the-box
  • Improves IDE suggestions and autocompletion
    • ... even if you don't use static typing in your code
    • no additional plugins required
  • 0% runtime overhead
    • not even a single import is required
  • 100% coverage of the public SciPy API
    • also covers most of the private API
  • Precise type-hinting of dtypes and shape-types
    • works with all "array-likes" and "dtype-likes"
    • many of the functions that return an array are shape-typed
    • shape-typing is optional: all functions still accept arrays with unknown shape-type
  • Type-checker agnostic
  • SPEC 0 compliant
    • Supports Python โ‰ฅ 3.10
    • Supports NumPy โ‰ฅ 1.24

Installation

PyPI Conda
pip install scipy-stubs
conda install conda-forge::scipy-stubs

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.

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.

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.

However, a small portion uses Untyped (an alias of Any) as "placeholder annotations". In those cases static type-checkers won't do any type-checking, and won't bother you with errors or warnings.

The following table shows the (subjective) proportion of scipy-stubs that is(n't) annotated with Untyped, ranging from ๐ŸŒ‘ (100% Untyped) to ๐ŸŒ• (0% Untyped).

scipy._ ruff & flake8-pyi stubtest basedmypy basedpyright phase
cluster โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ ๐ŸŒ•
constants โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ ๐ŸŒ
datasets โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ ๐ŸŒ
fft โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ ๐ŸŒ•
fftpack โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ ๐ŸŒ•
integrate โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ ๐ŸŒ•
interpolate โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ ๐ŸŒ“
io โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ ๐ŸŒ•
linalg โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ ๐ŸŒ•
misc โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ ๐ŸŒ•
ndimage โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ ๐ŸŒ•
odr โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ ๐ŸŒ•
optimize โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ ๐ŸŒ•
signal โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ ๐ŸŒ”
sparse โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ ๐ŸŒ’
spatial โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ ๐ŸŒ•
special โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ ๐ŸŒ•
stats โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ ๐ŸŒ•
_lib โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ ๐ŸŒ•

Currently, only interpolate, signal, and sparse contain Untyped annotations.

See also

  • scipy/scipy#21614: On why scipy-stubs is a separate package, and not part of scipy (yet).
  • microsoft/python-type-stubs#321: The removal of Microsoft's scipy-stubs โ€” that used to be bundled with Pylance โ€” in favor of scipy-stubs.
  • optype: The fundamental typing package that made scipy-stubs possible.
  • basedpyright: The recommended type-checker to use with scipy-stubs.
  • basedmypy: A less-broken mypy fork, with a bunch of cool extra features.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scipy_stubs-1.14.1.5.tar.gz (211.7 kB view details)

Uploaded Source

Built Distribution

scipy_stubs-1.14.1.5-py3-none-any.whl (386.1 kB view details)

Uploaded Python 3

File details

Details for the file scipy_stubs-1.14.1.5.tar.gz.

File metadata

  • Download URL: scipy_stubs-1.14.1.5.tar.gz
  • Upload date:
  • Size: 211.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.5

File hashes

Hashes for scipy_stubs-1.14.1.5.tar.gz
Algorithm Hash digest
SHA256 66c160c6b72b1406edc7827879ef25ea81dc3d95ab7e4af3a2de836f27c26ce6
MD5 6c03b7482d9e2c044171ac2650fcd63e
BLAKE2b-256 2e79d9a73d6c215b00b21ed16c6638c72a2ea25392f44348bd512fb7802f2ec4

See more details on using hashes here.

File details

Details for the file scipy_stubs-1.14.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for scipy_stubs-1.14.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 ca927802cae4c83e75b2a4b8c41271f36ebe0d928cee25ef3968e143b1793a75
MD5 49ebb4c648c73f4410e3c0ece120f2ad
BLAKE2b-256 5a01166738cea89ca8acacd46ef048b9ea37b5817373c7052bfaadbc6a95bc74

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page