{"id":2341,"library":"types-openpyxl","title":"Typing Stubs for openpyxl","description":"This is a type stub package for the `openpyxl` library, providing type hints for static analysis by tools like MyPy and Pyright. It aims to offer accurate annotations for specific `openpyxl` versions (e.g., `openpyxl==3.1.5` for `types-openpyxl 3.1.5.20260408`). `types-openpyxl` is part of the larger Typeshed project, which maintains type stubs for numerous Python libraries. It is actively maintained with frequent releases to keep up with `openpyxl` development.","status":"active","version":"3.1.5.20260408","language":"en","source_language":"en","source_url":"https://github.com/python/typeshed","tags":["typing","stubs","type-hints","excel","openpyxl","typeshed"],"install":[{"cmd":"pip install types-openpyxl openpyxl","lang":"bash","label":"Install stubs and the underlying library"}],"dependencies":[{"reason":"This package provides type stubs for openpyxl; openpyxl itself is a runtime dependency.","package":"openpyxl","optional":false},{"reason":"A static type checker that utilizes these stubs.","package":"mypy","optional":true},{"reason":"A static type checker that utilizes these stubs.","package":"pyright","optional":true}],"imports":[{"note":"types-openpyxl provides type hints for this import from the actual openpyxl library.","symbol":"Workbook","correct":"from openpyxl import Workbook"},{"note":"types-openpyxl provides type hints for this import from the actual openpyxl library.","symbol":"load_workbook","correct":"from openpyxl import load_workbook"},{"note":"types-openpyxl provides type hints for style-related imports from the actual openpyxl library.","symbol":"Font","correct":"from openpyxl.styles import Font"}],"quickstart":{"code":"import datetime\nfrom openpyxl import Workbook\nfrom openpyxl.styles import Font\n\ndef create_excel_with_types():\n    # This code uses openpyxl, and types-openpyxl provides type hints for it.\n    wb: Workbook = Workbook()\n    ws = wb.active\n    ws.title = \"Typed Sheet\"\n\n    # Type checking tools (like MyPy) will use types-openpyxl to validate these operations.\n    ws['A1'] = \"Date\"\n    ws['B1'] = \"Value\"\n    ws['A1'].font = Font(bold=True)\n    ws['B1'].font = Font(bold=True)\n\n    ws['A2'] = datetime.date(2026, 4, 9)\n    ws['B2'] = 123.45\n\n    file_path = \"typed_sample.xlsx\"\n    wb.save(file_path)\n    print(f\"Excel file '{file_path}' created with type hints verified.\")\n\nif __name__ == \"__main__\":\n    create_excel_with_types()","lang":"python","description":"This quickstart demonstrates basic usage of `openpyxl`. When `types-openpyxl` is installed alongside `openpyxl`, static type checkers like MyPy or Pyright can use the provided stubs to perform type verification on this code."},"warnings":[{"fix":"Ensure both `pip install openpyxl` and `pip install types-openpyxl` are run.","message":"This package provides *only* type stubs for `openpyxl`, not the `openpyxl` library itself. To use `openpyxl` with type hints, you must install both `openpyxl` and `types-openpyxl`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Refer to the `types-openpyxl` PyPI page or Typeshed documentation to find the `openpyxl` version the stubs are targeting. Ideally, keep `types-openpyxl` and `openpyxl` versions in sync, or at least close enough that their APIs don't diverge significantly.","message":"Type stubs are often tied to specific versions of the underlying library. While typeshed aims for broad compatibility, using `types-openpyxl` with an `openpyxl` version significantly different from the one it was generated for (e.g., `openpyxl==3.1.5` for `types-openpyxl 3.1.5.20260408`) may lead to incorrect type checking results.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If experiencing type checking issues after an `openpyxl` update, check if a newer `types-openpyxl` version is available. If not, consider reporting the discrepancy to the Typeshed project. Temporarily, you might need to use `type: ignore` comments if the code is known to be correct at runtime.","message":"Changes or bug fixes to `openpyxl`'s API (even minor ones) can lead to mismatches with the type stubs, causing type checkers to report errors on valid `openpyxl` code or fail to catch actual type errors. This is particularly relevant if `openpyxl` introduces new features or alters method signatures that are not yet reflected in the stubs.","severity":"breaking","affected_versions":"Potentially any `types-openpyxl` version when `openpyxl` updates."},{"fix":"To contribute, submit pull requests to the `typeshed` repository's `stubs/openpyxl` directory.","message":"All fixes and updates to the `openpyxl` type stubs should be contributed directly to the `python/typeshed` GitHub repository, not to the `types-openpyxl` PyPI package's maintainers directly. The PyPI package is automatically generated from Typeshed.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}