{"id":3191,"library":"openpyxl-stubs","title":"openpyxl-stubs","description":"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.","status":"active","version":"0.1.25","language":"en","source_language":"en","source_url":"https://github.com/MartinThoma/openpyxl-stubs","tags":["type-stubs","openpyxl","mypy","typing","excel"],"install":[{"cmd":"pip install openpyxl-stubs openpyxl","lang":"bash","label":"Install with openpyxl"}],"dependencies":[{"reason":"Provides type stubs for this library.","package":"openpyxl","optional":false}],"imports":[{"note":"Type stubs are automatically picked up by type checkers when `openpyxl-stubs` is installed. You import directly from `openpyxl`.","symbol":"Workbook","correct":"from openpyxl import Workbook"},{"note":"Type stubs are automatically picked up by type checkers when `openpyxl-stubs` is installed. You import directly from `openpyxl`.","symbol":"Worksheet","correct":"from openpyxl.worksheet.worksheet import Worksheet"}],"quickstart":{"code":"from openpyxl import Workbook\nfrom openpyxl.worksheet.worksheet import Worksheet\n\n# Create a new workbook with type hints\nwb: Workbook = Workbook()\n\n# Grab the active worksheet with type hints\nws: Worksheet = wb.active # type: ignore\n\n# Data can be assigned directly to cells\nws['A1'] = 42\n\n# Rows can also be appended\nws.append([1, 2, 3])\n\n# Python types will automatically be converted (example with a datetime object)\nimport datetime\nws['A2'] = datetime.datetime.now()\n\n# Save the file\n# In a real scenario, you'd use a temporary file or a specific path.\n# For this example, we'll just show the save operation.\n# wb.save(\"sample.xlsx\")\nprint(\"Workbook operations with type hints (stubs installed).\")","lang":"python","description":"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."},"warnings":[{"fix":"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`.","message":"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`.","severity":"deprecated","affected_versions":"<=0.1.25"},{"fix":"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.","message":"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.","severity":"gotcha","affected_versions":"<=0.1.25"},{"fix":"Ensure both `openpyxl` and `openpyxl-stubs` are installed: `pip install openpyxl openpyxl-stubs`.","message":"Installation of `openpyxl-stubs` alone does not provide the `openpyxl` functionality. It only provides type hints. You must install `openpyxl` separately.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}