This directory contains Python stub files (.pyi) that provide type hints and API documentation for the kintera package, which is implemented using pybind11 C++ bindings.
Stub files are special Python files with a .pyi extension that contain type signatures and documentation for modules without including the actual implementation. They are used by:
- Type checkers (mypy, pyright, etc.) to verify type correctness
- IDEs (VS Code, PyCharm, etc.) to provide autocomplete and documentation
- Documentation generators to extract API information
kintera.pyi- Main stub file containing all type signatures for the compiled pybind11 modulepy.typed- Marker file indicating this package supports type hints (PEP 561)
By separating the pybind11 implementation (python/csrc/*.cpp) from the API documentation (stub files), we achieve:
- Clear Documentation: Type hints and docstrings are in pure Python syntax
- Better IDE Support: IDEs can parse stub files to provide autocomplete
- Type Safety: Static type checkers can verify correct usage
- Maintainability: Documentation is separate from C++ binding code
- PEP 561 Compliance: Package properly declares type information
The stub files are automatically included when you install the package. Your IDE will automatically use them for autocomplete and type checking:
from kintera import ThermoOptions, ThermoX
import torch
# IDE will show autocomplete and parameter hints
options = ThermoOptions().Tref(300.0).Pref(1.e5)
thermo = ThermoX(options)
# Type checkers will verify correct types
temp = torch.tensor([300.0, 310.0])
pres = torch.tensor([1.e5, 1.e6])
xfrac = torch.tensor([0.1, 0.2])
result = thermo.forward(temp, pres, xfrac) # result is torch.TensorRun mypy to verify type correctness:
mypy your_script.pyWhen modifying the C++ bindings in python/csrc/, remember to update the corresponding type signatures in kintera.pyi:
- Add new classes or functions to the stub file
- Update parameter types and return types
- Include docstrings with examples
- Test with
mypyto ensure validity
See examples/test_type_hints.py for a demonstration of how the stub file enables type checking:
cd examples
mypy test_type_hints.pyThe actual pybind11 implementation is in:
python/csrc/kintera.cpp- Main module, SpeciesThermo, Reactionpython/csrc/pythermo.cpp- ThermoOptions, ThermoX, ThermoYpython/csrc/pykinetics.cpp- KineticsOptions, Kinetics, Arrheniuspython/csrc/pyconstants.cpp- Physical constants
The kintera.pyi stub file includes:
- All public classes with their methods
- Type signatures using Python's
typingmodule - Overloaded methods using
@overloaddecorator - Comprehensive docstrings with examples
- Module-level functions
- Constants submodule
The stub files are included in the package via pyproject.toml:
[tool.setuptools.package-data]
"kintera" = ["*.pyi", "py.typed", ...]- PEP 561 - Distributing and Packaging Type Information
- PEP 484 - Type Hints
- mypy - Optional Static Typing for Python
- pybind11 Documentation
When adding new features to the C++ bindings:
- Implement the binding in the appropriate
python/csrc/*.cppfile - Add the corresponding type signature to
kintera.pyi - Include docstrings with parameter descriptions and examples
- Run
mypyto validate the stub file - Test that IDEs can properly autocomplete the new features
This separation ensures that the API remains well-documented and type-safe while maintaining the performance benefits of C++ implementation.