pybind11-stubgen
PEP 561 type stubs generator for pybind11 modules
What it is and what it does
pybind11-stubgen is a command-line tool that introspects compiled Python extensions and generates PEP 561 type stub files (.pyi) for them. Binary extensions—whether built with pybind11, ctypes, or other C/C++ binding libraries—are normally opaque to static type checkers and IDEs because their signatures and types exist only at runtime in compiled code. This tool bridges that gap by extracting type information from the running module and writing it out as stub files that tools like mypy, pyright, and IDEs can read.
The tool is designed primarily for pybind11 modules but works with other binding approaches. It offers command-line options to handle edge cases like invalid expressions, unresolved names, and special handling for NumPy arrays. Once stubs are generated, they sit alongside your extension modules and enable full IDE autocomplete, type checking, and documentation generation for code that uses those extensions.
Use it for:
- Generate stubs for NumPy or other scientific C extensions so type checkers can validate code using them.
- Enable IDE autocomplete and inline documentation for third-party binary modules without source access.
- Create type stubs for in-house pybind11 modules to integrate them into a typed Python codebase.
- Support static analysis in CI/CD pipelines that use mypy or similar tools on code importing compiled extensions.
- Publish type information alongside a compiled extension package to improve downstream user experience.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Generates PEP 561 type stubs for Python binary extensions, making them visible to static analysis tools and IDEs by introspecting compiled modules.
Yes, if you work with Python binary extensions and want static type checking or IDE support for them. It has no runtime dependencies, low friction, and solves a real problem—making opaque compiled code visible to the Python tooling ecosystem. Install it as a development or build-time tool.
Install
pybind11-stubgen on PyPI
pip
pip install pybind11-stubgenuv
uv add pybind11-stubgenpoetry
poetry add pybind11-stubgenInstalling pybind11-stubgen
Before you install
Low install friction; no runtime dependencies. Actively maintained with recent commits and a steady release cadence since 2019.
License in practice
BSD license is permissive; you may use, modify, and distribute this package with minimal restrictions.
Quickstart
pip install pybind11-stubgen
pybind11-stubgen numpy
Requires Python ~=3.7 or later; the target module must be importable in the environment where stubs are generated.
Verify before relying
- How well stub generation works for non-pybind11 extensions (documentation mentions it 'should work well' but provides no compatibility matrix).
- Whether generated stubs are compatible with all major type checkers (mypy, pyright, etc.) or have known limitations.
Package facts
| License | BSD (permissive) |
| Python support | supports the current Python release (~=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 370 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,336,440/month — #4,032 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pybind11_stubgen-2.5.5-py3-none-any.whl
Tags
More Build Tools packages
Provides reusable utilities for Python…
permissive · top 100 on PyPI
tqdmWraps any iterable to display a real-time…
copyleft · top 100 on PyPI
pippip is the standard installer for Python…
permissive · top 100 on PyPI
hatchlingHatchling is a standards-compliant Python build…
permissive · top 100 on PyPI
grpcio-toolsGenerates Python gRPC service stubs and message…
permissive · top 1,000 on PyPI
pre-commitpre-commit is a framework for installing and…
permissive · top 1,000 on PyPI
types-enum34Provides type stubs for the enum34 package,…
permissive · top 15,000 on PyPI
docutils-stubsProvides PEP 561 type stubs for docutils,…
permissive · top 15,000 on PyPI
types-backportsProvides PEP 561 type stubs for the backports…
permissive · top 15,000 on PyPI
types-clickProvides PEP 561 type stubs for the click…
permissive · top 5,000 on PyPI
types-SQLAlchemyProvides PEP 561 type stubs for SQLAlchemy,…
permissive · top 15,000 on PyPI
types-attrsProvides PEP 561 type stubs for the attrs…
permissive · top 15,000 on PyPI
types-FlaskProvides PEP 561 type stubs for Flask to enable…
permissive · top 5,000 on PyPI
types-PillowProvides type stubs for Pillow, enabling static…
permissive · top 5,000 on PyPI
types-factory-boyProvides PEP 561 type stubs for factory-boy,…
permissive · top 15,000 on PyPI
pybind11pybind11 is a header-only C++ library that…
permissive · top 1,000 on PyPI