Registry / serialization / html2text

html2text

JSON →
library2025.4.15pypypi✓ verified 24d ago

html2text is a Python library that efficiently converts HTML into clean, easy-to-read plain ASCII text, which is also valid Markdown. It provides extensive customization options for the conversion process. The library maintains an active and healthy development status with regular releases, ensuring ongoing support and feature enhancements.

pip install html2text
INSTALL
IMPORT
SIG · HTML2TEXT
H
html2text
serializationpythonv2025.4.15
Install
1.6s avg
Import
62ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2025.4.15 · 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.062s · 18MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.062s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

HTML2Text
from html2text import HTML2Text
import html2text
html2text
from html2text import html2text
import html2text

This quickstart demonstrates both the simple `html2text()` function for basic conversion and the `HTML2Text` class for more granular control over the output, such as ignoring links or disabling line wrapping.

import html2text html_content = """ <h1>Welcome</h1> <p>Hello, <b>world</b>! This is a <a href="https://example.com">link</a>.</p> <ul> <li>Item 1</li> <li>Item 2</li> </ul> """ # Basic conversion plain_text = html2text.html2text(html_content) print("--- Basic Conversion ---") print(plain_text) # Custom conversion with options (e.g., ignoring links and no line wrapping) h = html2text.HTML2Text() h.ignore_links = True # Do not include link URLs h.body_width = 0 # Disable line wrapping custom_text = h.handle(html_content) print("\n--- Custom Conversion (No links, no wrap) ---") print(custom_text)
html2text --version
Debug
Known issues
breakingSupport for Python 2.x and older Python 3 versions was removed in release 2019.8.11. The library now officially requires Python 3.9 or newer.
fix
Upgrade your Python environment to 3.9 or newer.
affects: <2019.8.11
breakingThe functionality to retrieve HTML over the network by passing URLs directly to the library was removed in release 2019.8.11. Earlier versions issued deprecation warnings for this feature.
fix
Fetch HTML content using a dedicated HTTP client (e.g., `requests`) and pass the HTML string to `html2text.html2text()` or `HTML2Text().handle()`.
affects: <2019.8.11
gotchaTo configure conversion options (e.g., `ignore_links`, `body_width`, `images_as_html`), you must create an instance of `html2text.HTML2Text()` and set properties on it, then call its `handle()` method. The top-level `html2text.html2text()` function does not accept these configuration options directly.
fix
Use `h = html2text.HTML2Text(); h.option = True; h.handle(html)` for custom configurations.
affects: All
gotchaBy default, `html2text` may wrap long lines. To disable this, which is often desirable for programmatic parsing or specific Markdown formatting, set the `body_width` option to `0`.
fix
When using `HTML2Text()`, set `h.body_width = 0` to prevent line wrapping.
affects: All
Upgrade
Version history
2025.4.15latest on PyPI · released Apr 15, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
10
Resources
html2text — pip install html2text · libregistry