stubFileNotFound
is a collaborative project for creating and sharing Python stub files (.pyi
) for third-party Python packages. Stub files provide type hints and docstrings for modules, enabling better static analysis with tools like PyLance, pyright, and mypy and making it easier for developers to use the package.
-
Create or improve a stub file.
-
Submit a Pull Request.
To use the stub files from this repository:
-
Clone the repository.
git clone https://github.com/hunterhogan/stubFileNotFound.git
-
Tell your type checker about the
stubs
directory.
Relevant settings may include
python.analysis.stubPath
mypy-type-checker.args
"--custom-typeshed-dir=typings"
Virtual directories (symlinks)
(.venv) C:\apps\Z0Z_tools> MKLINK /D typings \apps\stubFileNotFound\stubs
-
Copy and paste the signature into a stub file. Improve it.
-
stubgen --verbose --include-docstrings ^ --include-private --output typings ^ --package nameOfAnInstalledPackage
VS Code:
workbench.action.openGlobalKeybindingsFile
{ "args": { "text": "stubgen --include-private --include-docstrings --output typings --verbose -p ${selectedText}\n" }, "command": "workbench.action.terminal.sendSequence", "key": "ctrl+shift+t" },
-
pyright --createstub nameOfAnInstalledPackage
- "Quick Fix" in VS Code.
-
Pylance if
reportMissingTypeStubs
is enabled and the stub is missing: "Quick Fix"
- MonkeyType
- stubgen-pyx:
stubgen-pyx /path/to/package
- stub-generator
-
Nuitka-Stubgen:
pip install AST-Stubgen
import pathlib import Ast_Stubgen pathlib.Path('typings/Ast_Stubgen').mkdir(parents=True, exist_ok=True) Ast_Stubgen.generate_stub('.venv/Lib/site-packages/Ast_Stubgen/stubgen.py', 'typings/Ast_Stubgen/stubgen.pyi') Ast_Stubgen.generate_stub('.venv/Lib/site-packages/Ast_Stubgen/__init__.py', 'typings/Ast_Stubgen/__init__.pyi')