openpyxl-stubs
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.
Warnings
- deprecated The `openpyxl-stubs` project has not been updated since January 2023 and is marked as '3 - Alpha' development status. It may not provide complete or accurate type coverage for recent versions of `openpyxl`.
- gotcha Due to its alpha status and infrequent updates, `openpyxl-stubs` might have missing modules, deprecated modules, or issues in annotations (e.g., missing parameter/return type annotations) compared to the actual `openpyxl` library.
- gotcha Installation of `openpyxl-stubs` alone does not provide the `openpyxl` functionality. It only provides type hints. You must install `openpyxl` separately.
Install
-
pip install openpyxl-stubs openpyxl
Imports
- Workbook
from openpyxl import Workbook
- Worksheet
from openpyxl.worksheet.worksheet import Worksheet
Quickstart
from openpyxl import Workbook
from openpyxl.worksheet.worksheet import Worksheet
# Create a new workbook with type hints
wb: Workbook = Workbook()
# Grab the active worksheet with type hints
ws: Worksheet = wb.active # type: ignore
# Data can be assigned directly to cells
ws['A1'] = 42
# Rows can also be appended
ws.append([1, 2, 3])
# Python types will automatically be converted (example with a datetime object)
import datetime
ws['A2'] = datetime.datetime.now()
# Save the file
# In a real scenario, you'd use a temporary file or a specific path.
# For this example, we'll just show the save operation.
# wb.save("sample.xlsx")
print("Workbook operations with type hints (stubs installed).")