pythonstubmypy

How can I get stub files for `matplotlib`, `numpy`, `scipy`, `pandas`, etc.?


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.?


Solution

  • 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

    For pandas, official stub support can be found in the pandas-stubs repository, which is the official pandas stubs project.

    There is no official support for stubs in Matplotlib, but you can check for community-contributed stubs or create your own if needed.

    In some cases, you might also find unofficial stubs in projects like data-science-types, but for the most up-to-date and reliable stubs, it's recommended to use the official sources mentioned above.