Skip to content

html2text

2,140 8 92 GPL-3.0
2025.4.15 (15 Apr 2025) Dec 14 2008 12.6 million (month)

html2text is a Python library that allows developers to convert HTML code into plain text. It is designed to be easy to use, and it provides several options to customize the output.

The package uses the python's built-in html.parser to parse the HTML and then convert it to plain text.

html2text also comes with a CLI tool that can convert HTML files to text:

```shell Usage: html2text [filename [encoding]]

Option Description --version Show program's version number and exit -h, --help Show this help message and exit --ignore-links Don't include any formatting for links --escape-all Escape all special characters. Output is less readable, but avoids corner case formatting issues. --reference-links Use reference links instead of links to create markdown --mark-code Mark preformatted and code blocks with [code]...[/code] ```

Example Use


```python import html2text

h = html2text.HTML2Text()

Ignore converting links from HTML

h.ignore_links = True print h.handle("

Hello, world!") "Hello, world!"

print(h.handle("

Hello, world!"))

"Hello, world!"

Don't Ignore links anymore, I like links

h.ignore_links = False print(h.handle("

Hello, world!")) "Hello, world!" ```

Alternatives / Similar


5,650 2.0.0 (2024-12-03 15:23:21 ago) Jul 17 2019 compare
2,894 0.8.4.1 (2025-05-03 21:11:43 ago) Jun 30 2011 compare
15,018 0.2.8 (2018-09-28 04:58:18 ago) Dec 28 2012 compare
961 0.18.0 (2024-11-08 14:59:22 ago) Oct 27 2015 compare
3,670 0.12.0 (2026-02-14 21:00:12 ago) Oct 20 2013 compare
12,807 1.1.9 (2018-10-21 03:39:17 ago) Aug 24 2018 compare
297 2.0.7 (2022-11-06 07:33:14 ago) Dec 11 2020 compare

Other Languages

2,824 v1.3.0 (2024-03-01 03:34:34 ago) Apr 20 2016 compare
Was this page helpful?