{"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":"python","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":[{"wrong":"import html5lib-stubs","symbol":"html5lib","correct":"import html5lib-stubs"}],"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,"search_vec":"'allow':16 'api':26 'chang':60 'check':10,67 'checker':18 'coincid':52 'continu':35 'frequent':50 'html':63 'html5lib':4,14,25,64 'librari':15,45,55 'like':19 'maintain':36 'mani':42 'mypi':20 'new':46 'often':51 'packag':6 'part':29 'popular':43 'project':33 'provid':7 'python':44,58 'releas':38,49 'static':8 'stub':2,11,40,62 'type':1,9,17,39,61,66 'type-check':65 'typesh':32,68 'updat':56 'upstream':54 'usag':23 'valid':22 'version':47,59","created_at":"2026-04-09T04:01:49.189725+00:00","updated_at":"2026-04-16T23:38:05.039113+00:00","problems":{"verify_error":"File \"<string>\", line 1\n    import html5lib-stubs\n                   ^\nSyntaxError: invalid syntax"},"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.1.11.20260518","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/typeshed-internal/stub_uploader","docs":null,"changelog":"https://github.com/typeshed-internal/stub_uploader/blob/main/data/changelogs/html5lib.md","pypi":"https://pypi.org/project/types-html5lib/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["type-stubs"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-07-03","last_verified":"2026-08-27","next_check":"2026-07-10","install_tag":null}}