Install & Compatibility
Where this runs
tested against v1.1.11.20260518 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 18MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 19MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
html5lib
✓ import html5lib-stubs
✗ import html5lib-stubs
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.
import html5lib
from html5lib.treebuilders import getTreeBuilder
import io
from typing import TextIO
# The types-html5lib package provides static type checking for html5lib.
# You use html5lib normally, and a type checker (like mypy) will use the stubs
# to validate your code.
# Example: Parsing HTML from a string
html_string: str = "<html><body><h1>Hello World</h1><p>This is a test.</p></body></html>"
# Initialize the parser with a tree builder (e.g., 'dom' for a DOM-like tree)
parser = html5lib.HTMLParser(tree=getTreeBuilder("dom"))
# Parse the HTML string
document = parser.parse(html_string)
# A type checker using types-html5lib would know the methods available on 'document'
# based on the 'dom' tree builder. For example, for a DOM tree:
if hasattr(document, 'getElementsByTagName'):
h1_elements = document.getElementsByTagName('h1')
if h1_elements:
print(f"First H1 tag content: {h1_elements[0].firstChild.nodeValue}")
# Example: Parsing from a file-like object
html_file_like: TextIO = io.StringIO("<html><head><title>Registry Entry</title></head><body></body></html>")
document_from_file = parser.parse(html_file_like)
if hasattr(document_from_file, 'getElementsByTagName'):
title_elements = document_from_file.getElementsByTagName('title')
if title_elements:
print(f"Document title from file: {title_elements[0].firstChild.nodeValue}")
print("html5lib parsing completed with type-checking support provided by types-html5lib.")
Debug
Known issues
gotchaType 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.fixEnsure both `html5lib` and `types-html5lib` are installed in your development environment: `pip install html5lib types-html5lib`.
affects: All versions
gotchaVersion 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.fixKeep `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`.
affects: All versions
breakingSignificant 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.fixWhen 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.
affects: All versions
deprecatedStubs 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.fixEnsure your project uses supported Python versions and relatively current versions of `html5lib` to benefit from ongoing `typeshed` maintenance.
affects: All versions (future versions might drop support)
Upgrade
Version history
1.1.11.20260518latest on PyPI · released May 18, 2026
Audit
Dependencies
html5librequiredThis package provides type hints for the `html5lib` library. `html5lib` must be installed at runtime for the code to execute.