I know that the stub files for built-in Python library for type checking and static analysis come with mypy
or PyCharm installation. How can I get stub files for matplotlib
, numpy
, scipy
, pandas
, etc.?

- 115,751
- 26
- 228
- 437

- 722
- 1
- 6
- 11
-
1See https://mypy.readthedocs.io/en/stable/getting_started.html#library-stubs-and-typeshed, they come from https://pypi.org/project/typeshed/ – jonrsharpe Feb 16 '20 at 09:44
-
@jonrsharpe Awesome! This really helps! – Sunghee Yun Feb 16 '20 at 18:56
-
7The packages you mentioned are not contained in `typeshed`. For `numpy`, there is an official [stub project](https://github.com/numpy/numpy-stubs) and can be installed via e.g. `pip install git+https://github.com/numpy/numpy-stubs`. For `pandas` etc, there are no official type hints yet, but lots of unofficial projects available, e.g. [`data-science-types`](https://pypi.org/project/data-science-types/). – hoefling Feb 16 '20 at 20:25
-
@hoefling This is great information. Thank you very much! – Sunghee Yun Feb 17 '20 at 03:38
-
2If anyone wonders in 2021, scipy is now typed since 1.5 release – krassowski Feb 16 '21 at 12:19
-
2@krassowski I have scipy 1.6.0, but mypy doesn't find its type stubs yet. – quant_dev Feb 17 '21 at 13:58
3 Answers
Type stubs are sometimes packaged directly with the library. Otherwise there can be some external libraries to provide them.
Numpy
Starting with numpy 1.20 type stubs will be included in numpy. See this changelog and this PR adding them
Before that they could added with the library https://github.com/numpy/numpy-stubs
Pandas and Matplotlib
There is no official support for these libraries stubs but you can find unofficial stubs in this project: https://pypi.org/project/data-science-types/
You can either install this library as a dependency or copy only the relevant part in the type stubs folder of your project.

- 2,768
- 3
- 30
- 44
-
-
It's not released yet, here is the milestone on github to follow the progress: https://github.com/numpy/numpy/milestone/83 – Fabich Aug 27 '20 at 09:01
-
4The data-science-types repo has been archived, and development has stopped. – bluenote10 Jul 14 '21 at 10:25
-
1
-
I am using numpy 1.23.5, but why does mypy still complain about "cannot find implementation or library stub for module named numpy"? – chenzhongpu Feb 15 '23 at 14:16
As of July 2022 there are official pandas stubs: https://github.com/pandas-dev/pandas-stubs
This is the home for pandas typing stubs supported by the pandas core team. The stubs are likely incomplete in terms of covering the published API of pandas.

- 474
- 9
- 21
If you are using VSCode and Pylance extension with strict type checking enabled, you can generate stub files automatically by just pressing quickfix option and press "Create Type Stub for "module" "

- 773
- 8
- 25