openpyxl-stubs provides type stubs for the openpyxl library, enabling static type checking with tools like MyPy. The current version is 0.1.25, released in January 2023, and it is currently in an alpha development status. It does not have a defined release cadence, as it is a stub package that augments the `openpyxl` library.
pip install openpyxl-stubs openpyxlVerified import paths — ran on the pinned version, not inferred.
This example demonstrates basic usage of openpyxl with type annotations. When `openpyxl-stubs` is installed, a type checker like MyPy will use its definitions to validate these operations. Note that `wb.active` might require a `# type: ignore` if the type checker has difficulty inferring `Worksheet` due to the dynamic nature of `active` property in some contexts without explicit stubs for that specific assignment, or if the stub is incomplete for that specific case. The actual save operation is commented out for quickstart runnability without file system interaction.
For up-to-date and more actively maintained type stubs for `openpyxl`, consider using `types-openpyxl` from the `typeshed` project, which is frequently updated and tracks newer `openpyxl` versions. Install with `pip install types-openpyxl`.
If you encounter type checking errors that seem incorrect or missing types, you may need to add `# type: ignore` comments or consider contributing fixes to the `openpyxl-stubs` repository. Switching to `types-openpyxl` is also recommended for better coverage.
Ensure both `openpyxl` and `openpyxl-stubs` are installed: `pip install openpyxl openpyxl-stubs`.