Registry / serialization / tinyhtml5

tinyhtml5

JSON →
library2.1.0pypypi✓ verified 26d ago

tinyhtml5 is a HTML5 parser, currently at version 2.1.0, that transforms a possibly malformed HTML document into an ElementTree tree. It is a simplified and modernized fork of the unmaintained `html5lib` library, focusing solely on parsing and generating `ElementTree` output. It typically releases updates to support new Python versions and minor feature enhancements.

pip install tinyhtml5
INSTALL
IMPORT
SIG · TINYHTML5
T
tinyhtml5
serializationpythonv2.1.0
Install
1.6s avg
Import
114ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.1.0 · 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
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.120s · 18.3MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.108s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse
from tinyhtml5 import parse
from html5lib import parse
tinyhtml5 is a fork of html5lib with a simplified API. Directly importing 'parse' from html5lib will use the original library, not tinyhtml5.

Parses an HTML string into an ElementTree object.

from tinyhtml5 import parse html_string = '<html><body><p>Hello, tinyhtml5!</p></body></html>' parsed_tree = parse(html_string) # The parsed_tree is an ElementTree object print(parsed_tree) print(parsed_tree.tag) print(parsed_tree[0].tag) print(parsed_tree[0][0].text)
Debug
Known issues
breakingPython 3.9 support was dropped in tinyhtml5 2.1.0. Python 3.10 or newer is now required. Users on older Python versions will need to use tinyhtml5 2.0.0 or earlier.
fix
Upgrade to Python 3.10+ or pin tinyhtml5 to '<2.1.0' if Python 3.9 is required.
affects: >=2.1.0
breakingtinyhtml5 is a simplified fork of `html5lib`. It only exposes a single `tinyhtml5.parse()` function that returns an `ElementTree` object. Many features present in `html5lib`, such as tree walkers, adapters, filters, and alternative tree builders (e.g., DOM, BeautifulSoup), are not supported in tinyhtml5.
fix
Carefully review the 'Going Further' documentation, especially the 'What are the differences with html5lib?' section, if migrating from `html5lib`. Adapt code to work solely with `ElementTree` for tree manipulation.
affects: >=2.0.0b1
gotchaThe only output format supported by `tinyhtml5` is ElementTree. If you are accustomed to working with other HTML parsing libraries like `BeautifulSoup` or `lxml` directly, you will receive an `ElementTree` object and may need to convert it or use `ElementTree`'s API for further processing.
fix
Familiarize yourself with the `xml.etree.ElementTree` API for navigating and manipulating the parsed HTML document, or explicitly convert the `ElementTree` to your preferred format/library.
affects: All
gotchaDirect indexing on ElementTree elements (e.g., `element[0]`) can result in `IndexError` if the element does not have a child at the specified index. This commonly occurs when an expected HTML element (like `<head>` or `<body>`) is empty or missing expected child nodes. Users should ensure elements have children before attempting to access them by index, or prefer methods like `element.find()` or `element.findall()` for safer navigation.
fix
Always check if an `ElementTree` element has children (e.g., `if len(element) > index:`) before direct indexing, or use `element.find('tag')` for single child lookups or `element.findall('tag')` for multiple, which return `None` or an empty list respectively when no matches are found, avoiding `IndexError`.
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'tinyhtml5'
The 'tinyhtml5' library is not installed in your Python environment.
fix
Install the library using pip: `pip install tinyhtml5`
ModuleNotFoundError: No module named 'tinyhtml5.treewalkers'
tinyhtml5 is a simplified fork of html5lib that focuses solely on parsing to ElementTree and does not include the 'treewalkers' module or other non-parsing components present in html5lib.
fix
tinyhtml5 does not provide 'treewalkers'. If you need to traverse the ElementTree generated by tinyhtml5, use standard ElementTree methods or process the output with another library.
AttributeError: module 'tinyhtml5' has no attribute 'HTMLParser'
tinyhtml5 does not expose a class named 'HTMLParser' directly under its top-level module; the parsing functions are located within the 'html5parser' submodule.
fix
Import the `html5parser` submodule and use its `parse` or `fromstring` functions: `from tinyhtml5 import html5parser` then `html5parser.parse(...)`.
TypeError: parse() got an unexpected keyword argument 'treebuilder'
tinyhtml5 is designed to only produce ElementTree output and does not accept a 'treebuilder' argument, unlike its predecessor html5lib.
fix
Remove the `treebuilder` argument, as tinyhtml5 defaults to ElementTree output: `from tinyhtml5 import html5parser` then `html5parser.parse(source)`.
Upgrade
Version history
2.1.0latest on PyPI · released Mar 5, 2026
Audit
Dependencies
webencodingsrequiredRequired for character encoding detection.
Agent activity
18 hits · last 30 days
node
14
OpenAI (training)
3
Resources