Typing stubs for ReportLab

4.4.10.20260408 · active · verified Sun Apr 12

types-reportlab provides static type checking annotations for the ReportLab library, enabling IDEs and type checkers (like Mypy or Pyright) to offer better autocompletion, error detection, and code understanding. It is part of the typeshed project, which collects high-quality type stubs for various Python packages. The current version, 4.4.10.20260408, aims to provide accurate annotations for reportlab==4.4.10 and is regularly updated as part of the typeshed release cycle, often reflecting changes in the upstream ReportLab library.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a basic PDF document using ReportLab's PLATYPUS API, with explicit type hints that `types-reportlab` would validate. Remember that `reportlab` itself must be installed for this code to run.

from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib.pagesizes import letter
from typing import List

def generate_simple_pdf(filename: str, title_text: str, paragraph_content: str) -> None:
    """Generates a simple PDF document using ReportLab with type hints."""
    doc: SimpleDocTemplate = SimpleDocTemplate(filename, pagesize=letter)
    story: List[Any] = [] # Use Any for flowables for simplicity here

    styles = getSampleStyleSheet()
    
    # Add a title
    title_style = styles['h1']
    title: Paragraph = Paragraph(title_text, title_style)
    story.append(title)
    story.append(Spacer(1, 0.2 * inch)) # type: ignore

    # Add a paragraph
    body_style = styles['Normal']
    paragraph: Paragraph = Paragraph(paragraph_content, body_style)
    story.append(paragraph)

    doc.build(story)
    print(f"PDF '{filename}' generated successfully.")

if __name__ == "__main__":
    from reportlab.lib.units import inch # type: ignore
    generate_simple_pdf(
        "hello_typed_report.pdf",
        "My Typed ReportLab Document",
        "This is a sample paragraph for a PDF generated using ReportLab, "
        "with type checking enhanced by types-reportlab stubs."
    )

view raw JSON →