html2text

Converts HTML into clean, readable Markdown-formatted plain text, as both a Python library and a CLI tool.

Library
PyPI
v2025.4.15
2,168stars
GNU GPLv3

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
49/100Fair
Development Activity0
Maintenance20
Community76
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
70/100Good
Architecture60
Code Quality72
Innovation58
Learning Curve90

html2text is a Python library and command-line tool that turns HTML markup into clean, readable plain text formatted as valid Markdown. Originally written by Aaron Swartz and now maintained by Alireza Savand, it walks the DOM with Python’s built-in html.parser and reconstructs headings, emphasis, lists, links, images, blockquotes, and tables as their Markdown equivalents, rather than simply stripping tags.

The library exposes a configurable HTML2Text class with dozens of toggles covering link handling, image alt-text defaults, table padding, line wrapping, and Unicode vs. ASCII punctuation, so callers can tune output for feeds, changelogs, email digests, or documentation pipelines. The bundled html2text CLI wraps the same options for one-off conversions from the shell, and the project ships an extensive golden-file test suite covering dozens of real-world HTML edge cases.

What You Get

  • HTML2Text class - a subclass of Python’s html.parser.HTMLParser that streams HTML and emits Markdown-formatted text incrementally.
  • Command-line tool - the html2text script for converting files or piped HTML from the shell without writing any Python.
  • Extensive configuration options - toggles for link style, image handling, table padding, line wrapping, and Unicode punctuation.
  • Google Docs export support - a google_doc mode that cleans up the inline styling Google Docs adds when exporting to HTML.

Common Use Cases

  • RSS/email digest generation - convert HTML feed entries or email bodies into readable plain-text summaries.
  • Documentation pipelines - normalize scraped or CMS-exported HTML into Markdown source for static site generators.
  • Content migration - bulk-convert legacy HTML content into Markdown when moving to a Markdown-based CMS or wiki.
  • Web scraping post-processing - clean up scraped HTML into readable text for search indexing or LLM context windows.

Under The Hood

Architecture HTML2Text subclasses Python’s stdlib html.parser.HTMLParser and overrides its tag/data handlers to build Markdown output incrementally into an internal text buffer, tracking nested state (lists, tables, blockquotes, anchors) via instance attributes and small helper dataclasses in elements.py. config.py centralizes every default toggle as a module-level constant, utils.py holds pure formatting helpers (escaping, Google-style CSS parsing, list numbering), and cli.py is a thin argparse adapter that instantiates HTML2Text and maps CLI flags onto its instance attributes. The layering is simple (config -> core parser class -> CLI adapter) with no dependency injection; because most state lives directly as attributes on one large parser subclass rather than an isolated state object, changing the core tag-handling logic tends to ripple across many of the class’s methods.

Tech Stack The runtime has zero dependencies — it relies entirely on the Python standard library (html.parser, re, string, urllib.parse, textwrap). Packaging uses setuptools with setuptools_scm for git-tag-derived versioning, written to html2text/_version.py at build time. Dev tooling includes pytest for tests, tox for a multi-version test matrix, mypy for type checking (the package ships a py.typed marker), and Flake8, Black, and isort for linting/formatting, all pinned in pyproject.toml. CI runs on GitHub Actions with a separate workflow for PyPI publishing, and Codecov tracks coverage.

Code Quality Tests live in test/test_html2text.py and drive a golden-file harness that iterates dozens of paired .html/.md fixtures, running each through both the Python API and the CLI subprocess to check output parity — solid regression coverage, though it’s snapshot-style rather than unit tests of individual internal methods. Typing is present via a py.typed marker and mypy configuration, though the core module mixes typed and loosely-typed sections. There’s no custom exception hierarchy; parsing errors mostly surface as whatever html.parser raises. Naming is consistent snake_case throughout, and CI enforces flake8/black/mypy via a dedicated tox environment.

API Design The public surface is minimal and idiomatic: html2text.html2text(html_string) for one-shot conversion, or html2text.HTML2Text() for a configurable instance with a .handle() method. Configuration is exposed as plain instance attributes (bodywidth, ignore_links, wrap_tables, and so on) rather than a dedicated config object, which keeps the common case terse but makes the full option surface hard to discover without reading the source or docs/usage.md. Documentation covers the basics well, though the CLI’s roughly thirty flags are where most individual options are actually explained.

Used by 7 apps in this directory

Python
62%
MIT

AutoGen

AI Development · Automation

60,698

Build autonomous and human-in-the-loop multi-agent AI systems with a layered, event-driven Python and .NET framework pioneered at Microsoft Research.

View details
56
Repo Health
78
Technical
74
Dependency
Built with
Python62%
C#25%
TypeScript12%
Updated 4 months ago
Python
67%
Other

AutoGPT

Automation · Productivity · AI Assistants

186,997

Build, deploy, and run autonomous AI agents that automate complex multi-step workflows using a visual block-based graph editor.

View details
93
Repo Health
78
Technical
67
Dependency
Built with
Python67%
TypeScript31%
Updated today
TypeScript
94%
Other

OpenHands

AI Code Assistants · AI Development

85,609

The self-hosted developer control center for running AI coding agents — locally, in Docker, on VMs, or across cloud backends — with automation workflows for GitHub, Slack, and more.

View details
91
Repo Health
82
Technical
71
Dependency
Built with
TypeScript94%
Updated today
Python
74%
AGPL 3.0

OpenViking

Databases · AI Development

34,389

An open-source context database that gives AI agents a unified filesystem for memory, resources, and skills with hierarchical tiered retrieval.

View details
84
Repo Health
75
Technical
65
Dependency
Built with
Python74%
Rust14%
Updated today
Python
86%
Apache 2.0

PrivateGPT

AI Development

57,490

The open-source API layer that turns local LLMs into production private AI applications with full Claude API compatibility

View details
87
Repo Health
83
Technical
71
Dependency
Built with
Python86%
HTML10%
Updated 2 days ago
JavaScript
50%
AGPL 3.0

QRev

CRM · AI Agents

361

Open source AI-first sales platform that replaces Salesforce with autonomous agents handling prospecting, outreach, and lead management at scale.

View details
39
Repo Health
68
Technical
65
Dependency
Built with
JavaScript50%
Python28%
TypeScript14%
Updated 6 months ago
Python
91%
GPL 3.0

Weblate

Developer Tools

6,043

Continuous localization platform that commits translations directly into your version control system with full translator attribution.

View details
95
Repo Health
86
Technical
73
Dependency
Built with
Python91%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search