{"id":4829,"library":"types-reportlab","title":"Typing stubs for ReportLab","description":"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.","status":"active","version":"4.4.10.20260408","language":"en","source_language":"en","source_url":"https://github.com/python/typeshed","tags":["typing","stubs","type hints","reportlab","pdf","typeshed"],"install":[{"cmd":"pip install types-reportlab","lang":"bash","label":"Install types-reportlab"},{"cmd":"pip install reportlab Pillow","lang":"bash","label":"Install ReportLab and dependencies (required for runtime)"}],"dependencies":[{"reason":"Provides the runtime functionality for which these stubs offer type hints. types-reportlab targets reportlab==4.4.10.","package":"reportlab","optional":false},{"reason":"ReportLab uses Pillow for image handling.","package":"Pillow","optional":true},{"reason":"Required Python version.","package":"python","optional":false}],"imports":[{"note":"Used for low-level, direct drawing onto the PDF page.","symbol":"Canvas","correct":"from reportlab.pdfgen.canvas import Canvas"},{"note":"Part of the higher-level PLATYPUS API for structured document generation.","symbol":"SimpleDocTemplate","correct":"from reportlab.platypus import SimpleDocTemplate"},{"note":"For adding formatted text paragraphs to a PLATYPUS document.","symbol":"Paragraph","correct":"from reportlab.platypus import Paragraph"},{"note":"For creating tabular data structures within a PLATYPUS document.","symbol":"Table","correct":"from reportlab.platypus import Table"},{"note":"Provides a collection of predefined styles for text and paragraphs.","symbol":"getSampleStyleSheet","correct":"from reportlab.lib.styles import getSampleStyleSheet"},{"note":"A common predefined page size (e.g., US Letter).","symbol":"letter","correct":"from reportlab.lib.pagesizes import letter"},{"note":"Provides predefined color constants.","symbol":"colors","correct":"from reportlab.lib import colors"}],"quickstart":{"code":"from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer\nfrom reportlab.lib.styles import getSampleStyleSheet\nfrom reportlab.lib.pagesizes import letter\nfrom typing import List\n\ndef generate_simple_pdf(filename: str, title_text: str, paragraph_content: str) -> None:\n    \"\"\"Generates a simple PDF document using ReportLab with type hints.\"\"\"\n    doc: SimpleDocTemplate = SimpleDocTemplate(filename, pagesize=letter)\n    story: List[Any] = [] # Use Any for flowables for simplicity here\n\n    styles = getSampleStyleSheet()\n    \n    # Add a title\n    title_style = styles['h1']\n    title: Paragraph = Paragraph(title_text, title_style)\n    story.append(title)\n    story.append(Spacer(1, 0.2 * inch)) # type: ignore\n\n    # Add a paragraph\n    body_style = styles['Normal']\n    paragraph: Paragraph = Paragraph(paragraph_content, body_style)\n    story.append(paragraph)\n\n    doc.build(story)\n    print(f\"PDF '{filename}' generated successfully.\")\n\nif __name__ == \"__main__\":\n    from reportlab.lib.units import inch # type: ignore\n    generate_simple_pdf(\n        \"hello_typed_report.pdf\",\n        \"My Typed ReportLab Document\",\n        \"This is a sample paragraph for a PDF generated using ReportLab, \"\n        \"with type checking enhanced by types-reportlab stubs.\"\n    )\n","lang":"python","description":"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."},"warnings":[{"fix":"Ensure `pip install reportlab` (and optionally `pip install Pillow`) is run in your environment alongside `pip install types-reportlab`.","message":"Installing `types-reportlab` alone does NOT provide runtime functionality. It only provides type annotations. You must install the actual `reportlab` library (and its dependencies like `Pillow` for images) separately for your code to execute.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Match the `types-reportlab` stub version as closely as possible to your `reportlab` runtime version. Consider using version specifiers in your `requirements.txt` (e.g., `types-reportlab~=4.4.10`).","message":"Type checking failures may occur if the version of `types-reportlab` does not align with your installed `reportlab` version. `types-reportlab` versions are specifically tailored to a corresponding `reportlab` version (e.g., `4.4.10.20260408` targets `reportlab==4.4.10`).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Address new type checker errors by adjusting your code to conform to the corrected type hints, or temporarily pin the `types-reportlab` version if immediate changes are not feasible.","message":"While stub packages themselves don't typically 'break' runtime code, updates to `typeshed` stubs can introduce stricter type checking rules or corrections that might cause existing code to fail type checking, even if the runtime behavior of `reportlab` hasn't changed.","severity":"breaking","affected_versions":"All versions (with typeshed updates)"},{"fix":"Consult community resources, blog posts, and thoroughly explore the ReportLab API reference and source code for deeper understanding beyond the official user guide. Experimentation with `dir()` and an interactive debugger (`ipdb`) can also be helpful.","message":"ReportLab's documentation can sometimes be challenging to navigate, with some examples considered outdated or incomplete by community members, leading to difficulties in finding specific patterns or features.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}