Typing Stubs for openpyxl

3.1.5.20260408 · active · verified Thu Apr 09

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.

Warnings

Install

Imports

Quickstart

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.

import datetime
from openpyxl import Workbook
from openpyxl.styles import Font

def create_excel_with_types():
    # This code uses openpyxl, and types-openpyxl provides type hints for it.
    wb: Workbook = Workbook()
    ws = wb.active
    ws.title = "Typed Sheet"

    # Type checking tools (like MyPy) will use types-openpyxl to validate these operations.
    ws['A1'] = "Date"
    ws['B1'] = "Value"
    ws['A1'].font = Font(bold=True)
    ws['B1'].font = Font(bold=True)

    ws['A2'] = datetime.date(2026, 4, 9)
    ws['B2'] = 123.45

    file_path = "typed_sample.xlsx"
    wb.save(file_path)
    print(f"Excel file '{file_path}' created with type hints verified.")

if __name__ == "__main__":
    create_excel_with_types()

view raw JSON →