{"id":1757,"library":"types-html5lib","title":"Typing Stubs for html5lib","description":"This package provides static type checking stubs for the `html5lib` library, allowing type checkers like MyPy to validate usage of `html5lib` APIs. It's part of the `typeshed` project, which continuously maintains and releases type stubs for many popular Python libraries. New versions are released frequently, often coinciding with upstream library updates or Python version changes.","status":"active","version":"1.1.11.20260408","language":"en","source_language":"en","source_url":"https://github.com/python/typeshed/tree/main/stubs/html5lib","tags":["typing","stubs","html","html5lib","type-checking","typeshed"],"install":[{"cmd":"pip install types-html5lib","lang":"bash","label":"Install `types-html5lib`"}],"dependencies":[{"reason":"This package provides type hints for the `html5lib` library. `html5lib` must be installed at runtime for the code to execute.","package":"html5lib","optional":false}],"imports":[{"note":"Type checkers (e.g., MyPy) automatically discover and use these stubs when you import symbols from the `html5lib` package. You do not import directly from `types_html5lib` at runtime.","wrong":"from types_html5lib import HTMLParser","symbol":"html5lib","correct":"import html5lib"},{"note":"The stubs provide type information for classes and functions within the `html5lib` library.","symbol":"html5lib.HTMLParser","correct":"from html5lib import HTMLParser"}],"quickstart":{"code":"import html5lib\nfrom html5lib.treebuilders import getTreeBuilder\nimport io\nfrom typing import TextIO\n\n# The types-html5lib package provides static type checking for html5lib.\n# You use html5lib normally, and a type checker (like mypy) will use the stubs\n# to validate your code.\n\n# Example: Parsing HTML from a string\nhtml_string: str = \"<html><body><h1>Hello World</h1><p>This is a test.</p></body></html>\"\n\n# Initialize the parser with a tree builder (e.g., 'dom' for a DOM-like tree)\nparser = html5lib.HTMLParser(tree=getTreeBuilder(\"dom\"))\n\n# Parse the HTML string\ndocument = parser.parse(html_string)\n\n# A type checker using types-html5lib would know the methods available on 'document'\n# based on the 'dom' tree builder. For example, for a DOM tree:\nif hasattr(document, 'getElementsByTagName'):\n    h1_elements = document.getElementsByTagName('h1')\n    if h1_elements:\n        print(f\"First H1 tag content: {h1_elements[0].firstChild.nodeValue}\")\n\n# Example: Parsing from a file-like object\nhtml_file_like: TextIO = io.StringIO(\"<html><head><title>Registry Entry</title></head><body></body></html>\")\ndocument_from_file = parser.parse(html_file_like)\n\nif hasattr(document_from_file, 'getElementsByTagName'):\n    title_elements = document_from_file.getElementsByTagName('title')\n    if title_elements:\n        print(f\"Document title from file: {title_elements[0].firstChild.nodeValue}\")\n\nprint(\"html5lib parsing completed with type-checking support provided by types-html5lib.\")","lang":"python","description":"This quickstart demonstrates basic usage of the `html5lib` library. When `types-html5lib` is installed, a static type checker (like MyPy) will use these stubs to provide type validation and autocompletion for `html5lib`'s APIs, without any explicit import statements for the stub package itself."},"warnings":[{"fix":"Ensure both `html5lib` and `types-html5lib` are installed in your development environment: `pip install html5lib types-html5lib`.","message":"Type stubs are for static analysis only. Installing `types-html5lib` does not install the actual `html5lib` library, nor does it make `html5lib` imports runnable if `html5lib` is not installed. Both packages are typically needed: `html5lib` for runtime execution and `types-html5lib` for type checking.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Keep `types-html5lib` updated, ideally alongside `html5lib`, to ensure compatibility. If you pin `html5lib` to an older version, you may need to find a compatible older version of `types-html5lib`.","message":"Version mismatches between the `types-html5lib` stubs and the actual `html5lib` library can lead to incorrect or missing type hints. Stubs are developed against specific versions of the underlying library.","severity":"gotcha","affected_versions":"All versions"},{"fix":"When upgrading `html5lib`, also upgrade `types-html5lib` and run your type checker. Adjust your code to align with the new `html5lib` API as indicated by the type checker.","message":"Significant API changes in the `html5lib` library itself will be reflected in subsequent `types-html5lib` releases. This can cause type-checking errors (e.g., 'missing attribute', 'unexpected argument') in code that was previously valid against older stubs.","severity":"breaking","affected_versions":"All versions"},{"fix":"Ensure your project uses supported Python versions and relatively current versions of `html5lib` to benefit from ongoing `typeshed` maintenance.","message":"Stubs for older Python versions or very old `html5lib` versions may eventually be dropped from `typeshed`. This means `types-html5lib` might cease to provide support for specific legacy environments.","severity":"deprecated","affected_versions":"All versions (future versions might drop support)"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}