pybind/pybind11-stubgen

Generate stubs for python modules

Python

361

329 commits

updated Aug 4, 2026

See the code

README

pypi

About

Static analysis tools and IDE usually struggle to understand python binary extensions. pybind11-stubgen generates stubs for python extensions to make them less opaque.

While the CLI tool includes tweaks to target modules compiled specifically with pybind11 but it should work well with modules built with other libraries.

# Install
pip install pybind11-stubgen

# Generate stubs for numpy
pybind11-stubgen numpy

Usage

pybind11-stubgen [-h]
                 [-o OUTPUT_DIR]
                 [--root-suffix ROOT_SUFFIX]
                 [--ignore-invalid-expressions REGEX]
                 [--ignore-invalid-identifiers REGEX]
                 [--ignore-unresolved-names REGEX]
                 [--ignore-all-errors]
                 [--enum-class-locations REGEX:LOC]
                 [--numpy-array-wrap-with-annotated|
                  --numpy-array-use-type-var|
                  --numpy-array-remove-parameters]
                 [--print-invalid-expressions-as-is]
                 [--print-value-comments]
                 [--print-safe-value-reprs REGEX]
                 [--exit-code]
                 [--stub-extension EXT]
                 MODULE_NAME [MODULE_NAMES ...]

Contributing

During development, you may need to update the reference stubs in tests/stubs. This can be done locally using a convenience tox configuration. Ensure that all Python interpreters required by the test suite are available in your environment. For example, you can install them via uv:

uv python install 3.10 3.11 3.12 3.13

To enable the repository hooks locally:

uv sync
uv run pre-commit install

To regenerate the reference stubs run:

uv venv
source .venv/bin/activate
uv tool install tox --with tox-uv
uv run tox
mypy
pep484
pep561
pybind11
pycharm
python
typing

Contributors

sizmailov

259 commits

gentlegiantJGC

11 commits

ax3l

9 commits

virtuald

5 commits

pybind/pybind11-stubgen

Generate stubs for python modules

Python

361

329 commits

updated Aug 4, 2026

See the code

README

pypi

About

Static analysis tools and IDE usually struggle to understand python binary extensions. pybind11-stubgen generates stubs for python extensions to make them less opaque.

While the CLI tool includes tweaks to target modules compiled specifically with pybind11 but it should work well with modules built with other libraries.

# Install
pip install pybind11-stubgen

# Generate stubs for numpy
pybind11-stubgen numpy

Usage

pybind11-stubgen [-h]
                 [-o OUTPUT_DIR]
                 [--root-suffix ROOT_SUFFIX]
                 [--ignore-invalid-expressions REGEX]
                 [--ignore-invalid-identifiers REGEX]
                 [--ignore-unresolved-names REGEX]
                 [--ignore-all-errors]
                 [--enum-class-locations REGEX:LOC]
                 [--numpy-array-wrap-with-annotated|
                  --numpy-array-use-type-var|
                  --numpy-array-remove-parameters]
                 [--print-invalid-expressions-as-is]
                 [--print-value-comments]
                 [--print-safe-value-reprs REGEX]
                 [--exit-code]
                 [--stub-extension EXT]
                 MODULE_NAME [MODULE_NAMES ...]

Contributing

During development, you may need to update the reference stubs in tests/stubs. This can be done locally using a convenience tox configuration. Ensure that all Python interpreters required by the test suite are available in your environment. For example, you can install them via uv:

uv python install 3.10 3.11 3.12 3.13

To enable the repository hooks locally:

uv sync
uv run pre-commit install

To regenerate the reference stubs run:

uv venv
source .venv/bin/activate
uv tool install tox --with tox-uv
uv run tox
mypy
pep484
pep561
pybind11
pycharm
python
typing

Contributors

sizmailov

259 commits

gentlegiantJGC

11 commits

ax3l

9 commits

virtuald

5 commits

Languages

Python

93.6%

C++

4.9%

Shell

1.1%