html-table-rescuer
A robust Python tool to extract complex HTML tables and convert them into clean Markdown, JSON, or CSV formats.
Try it in your browser — an interactive Colab notebook, nothing to install.
Unlike simple formatters, this library features a Grid Logic Solver that correctly interprets rowspan and colspan attributes, normalizing complex HTML grids into perfectly aligned data structures.
How is this different from other table2md packages?
There is an existing package called table2md on PyPI.
-
The existing package is a formatter. You feed it Python lists/dicts, and it draws a Markdown table.
-
This package is an extractor and parser. It takes raw HTML source code, uses
BeautifulSoupto parse the tags, mathematically resolves complex cell spans (rowspans/colspans), and builds an internal representation before exporting to Markdown.
The Problem:
Most parsers turn this <td rowspan="2"> into a misaligned mess:
| Header | Value |
|---|---|
| Spanned | Row 1 |
| Row 2 | | <-- Everything shifts!
The Solution:
html-table-rescuer uses a grid solver to correctly normalize the matrix:
| Header | Value |
|---|---|
| Spanned | Row 1 |
| dito (Spanned) | Row 2 |
Architecture
Our pipeline ensures that complex HTML structures are safely converted without data loss or misalignment:
graph TD
n1["HTML Input"] --> n2["BeautifulSoup Parser"]
n2 --> n3["Grid Logic<br>(Rowspan/Colspan Solver)"]
n3 --> n4["ParsedTable Data Object"]
n4 --> n5["Markdown Export"]
n4 --> n6["JSON/CSV Export"]
n4 --> n7["LangChain/LlamaIndex/Haystack Wrappers"]
Installation
pip install html-table-rescuer
# With framework integrations
pip install "html-table-rescuer[langchain]"
pip install "html-table-rescuer[llamaindex]"
pip install "html-table-rescuer[haystack]"
Quick Start
from html_table_rescuer import TableParser
html_content = """
<table border="1">
<tr>
<th colspan="2">Header</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
</table>
"""
# Initialize parser with your HTML
parser = TableParser(html_content)
# Parse all tables in the HTML
tables = parser.parse()
if tables:
table = tables[0]
# Export to Markdown (perfect for LLM context windows)
print(table.to_markdown())
# Export to JSON
# print(table.to_json())
# Export to CSV
# print(table.to_csv())
Command Line
The package installs an html-table-rescuer command that reads from a file, a URL, or stdin:
# From a file
html-table-rescuer page.html
# From a URL
html-table-rescuer https://example.com/page.html
# From stdin (pipe or '-')
curl -s https://example.com/page.html | html-table-rescuer
cat page.html | html-table-rescuer - --format json
Options:
| Option | Description |
|---|---|
--format, -f |
Output format: markdown (default), json, csv |
--strategy, -s |
Rowspan fill strategy: fill_dito (default), repeat, empty |
--dito-prefix |
Prefix used by the fill_dito strategy |
--table, -t |
Extract only the table with this index (0-based) |
--output, -o |
Write to a file instead of stdout; with CSV and multiple tables, writes name_1.csv, name_2.csv, … |
--no-links / --no-bold / --no-italic |
Strip the respective inline formatting |
--parser |
BeautifulSoup backend (lxml default, or html.parser) |
AI Framework Integrations
Every table becomes its own document, so retrieval never splits a table in half.
LangChain
from html_table_rescuer.integrations.langchain import HTMLTableRescuerLoader
docs = HTMLTableRescuerLoader("page.html").load()
print(docs[0].page_content) # Markdown table
print(docs[0].metadata) # {'source': 'page.html', 'table_index': 0, 'parser': 'html_table_rescuer'}
LlamaIndex
from html_table_rescuer.integrations.llamaindex import HTMLTableRescuerReader
docs = HTMLTableRescuerReader().load_data("page.html")
Works as a file_extractor in SimpleDirectoryReader, so entire folders are handled for you:
from llama_index.core import SimpleDirectoryReader
reader = SimpleDirectoryReader(
"./docs",
file_extractor={".html": HTMLTableRescuerReader()},
)
docs = reader.load_data()
Haystack
from html_table_rescuer.integrations.haystack import HTMLTableRescuerConverter
converter = HTMLTableRescuerConverter()
docs = converter.run(sources=["page.html"])["documents"]
Drops straight into a pipeline — unreadable sources are skipped with a warning
rather than failing the run, and ParseConfig survives pipeline serialization:
from haystack import Pipeline
pipe = Pipeline()
pipe.add_component("converter", HTMLTableRescuerConverter())
result = pipe.run({"converter": {"sources": ["page.html"]}})
All three accept a ParseConfig to control rowspan handling and inline formatting:
from html_table_rescuer import ParseConfig, RowspanStrategy
config = ParseConfig(rowspan_strategy=RowspanStrategy.REPEAT_VALUE)
docs = HTMLTableRescuerReader(config=config).load_data("page.html")
Features
- HTML parsing via
BeautifulSoup - Recursive inline-tag formatting (keeps links, bold, and italic tags alive even if nested in divs)
- Complex
rowspanandcolspangrid resolution (using flexible strategies like filling cells with "dito" to preserve context for LLMs) - Clean Markdown export
- Data Exports: JSON and CSV serialization from the
ParsedTableobject - CLI:
html-table-rescuercommand with file/URL/stdin input and Markdown/JSON/CSV output - AI Integrations: Ready-to-use
LangChainDocument Loader,LlamaIndexReader (works withSimpleDirectoryReader), andHaystackConverter - Robust against broken real-world HTML: invalid
colspan/rowspanvalues, HTML comments, and oversized spans are handled gracefully
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License.
Blog-Posts:
** Read the 1. blog:** How to Stop LLMs from Hallucinating on Complex HTML Tables ** Read the 2. blog:** How to Stop LLMs from Hallucinating on Complex HTML Tables
Metadata
Release files for html-table-rescuer 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| html_table_rescuer-0.3.1.tar.gz | 22.7 kB | With provenance | Details for html_table_rescuer-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| html_table_rescuer-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for html_table_rescuer-0.3.1-py3-none-any.whl |
Total release size: 39.2 kB
Release files / html_table_rescuer-0.3.1.tar.gz
| Download URL | html_table_rescuer-0.3.1.tar.gz |
|---|---|
| Size | 22.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7ca2c81ebfed2d4edade1eb79d4ca9b04cdd2c20720806fae28b95959d875287
|
|
BLAKE2b-256 checksum How to use checksums |
b0eae278e8f4fc0ed01bd7abab2c7ccd47d296cd69c4e181bc453f8e2499e773
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 30, 2026.
Transparency logRelease files / html_table_rescuer-0.3.1-py3-none-any.whl
| Download URL | html_table_rescuer-0.3.1-py3-none-any.whl |
|---|---|
| Size | 16.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
84287d24344a1316b31b6a28118b6e486cfc6963099a7e31faca2f7c79734b22
|
|
BLAKE2b-256 checksum How to use checksums |
4c1d9ed6c3b53ac8a1dcd397cf1c594085f318477cbd9fed46d0b9b69ac6ae32
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 30, 2026.
Transparency logSecurity for html-table-rescuer 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for html_table_rescuer-0.3.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 30, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.