Registry / data / readability-lxml

readability-lxml

JSON →
library0.9pypypi✓ verified 25d ago

readability-lxml is a Python library that provides a fast HTML to text parser, designed to extract and clean up the main body text and title from an HTML document. It is a Python port of a Ruby port of arc90's Readability project. The library is actively maintained, with the latest version being 0.8.4.1 as of May 2025 (last PyPI upload date), and new releases typically occur to add Python version support, fix bugs, or add minor features.

pip install readability-lxml
INSTALL
IMPORT
SIG · READABILITY-LXML
R
readability-lxml
datapythonv0.9
Install
2.4s avg
Import
376ms
Disk
30MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.9 · 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.398s · 32.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.4s · import 0.354s · 33MB
30MB installed
● package 30MB
Code
Verified usage

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

Document
from readability import Document
from readability.readability import Document
The more direct `from readability import Document` is the current and recommended import path; older examples might use `from readability.readability import Document`.

This quickstart fetches HTML content from a URL (or uses a fallback) using `requests`, then uses `readability-lxml` to extract the article's title and a cleaned HTML summary. It also demonstrates how to get a plain text version from the summary HTML using `lxml.html`.

import requests from readability import Document import os # For example usage, though not strictly required by readability-lxml itself from lxml.html import fromstring # For plain text conversion # Replace with a real URL or local HTML content url = os.environ.get('READABILITY_TEST_URL', 'http://example.com') try: response = requests.get(url, timeout=10) response.raise_for_status() # Raise an exception for HTTP errors html_content = response.content except requests.exceptions.RequestException as e: print(f"Error fetching URL: {e}") html_content = b"<html><body><h1>Default Title</h1><p>This is some example content.</p></body></html>" doc = Document(html_content) title = doc.title() summary_html = doc.summary() print(f"Title: {title}") print("Summary HTML (first 500 chars):") print(summary_html[:500]) # Optional: Get a plain text version (strip tags) using lxml.html clean_doc = fromstring(summary_html) print("\nSummary Text (first 200 chars):") print(clean_doc.text_content()[:200])
Debug
Known issues
breakingVersion 0.8 replaced XHTML output with HTML5 output in the `summary()` call. If your application was expecting strict XHTML, this change could break parsing or rendering logic.
fix
Update downstream parsers or consumers of `summary()` output to handle HTML5, or implement a conversion step if strict XHTML is required.
affects: 0.8 and later
gotchaThere is a potential import name collision with the `py-readability-metrics` library, as both attempt to import a `Document` class from a top-level `readability` package. Using both in the same environment can lead to one overriding the other.
fix
To use both libraries, it is recommended to isolate them in separate virtual environments or implement advanced importlib techniques to alias one of the modules.
affects: All versions
gotchaThe library relies on `lxml` which in turn requires `libxml2` and `libxslt` C libraries. While `pip install` often handles binary wheels, source builds on some platforms (like macOS or Linux distributions without pre-packaged dev libraries) might require manual installation of these system dependencies.
fix
Ensure `libxml2-dev` and `libxslt-dev` (or equivalent development packages for your OS) are installed before attempting to install `lxml` or `readability-lxml` from source.
affects: All versions
deprecatedWhile older versions (up to 0.6) explicitly supported Python 2.6, 2.7, 3.3, 3.4, the project summary now states 'python 3 support' and recent updates focus on Python 3.7+ (up to 3.13). Python 2.x support is effectively deprecated and likely broken in current versions.
fix
Migrate to Python 3.x if still on Python 2.x. Use `readability-lxml` 0.6 or older if strict Python 2.x compatibility is required (not recommended due to security and lack of maintenance).
affects: Versions after 0.6; fully deprecated in 0.7+
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'readability'
The 'readability-lxml' package is not installed or not available in the current Python environment.
fix
Install the package using pip: 'pip install readability-lxml'.
ImportError: cannot import name 'Document' from 'readability'
The 'readability-lxml' package is not installed or the import statement is incorrect.
fix
Ensure the package is installed and use the correct import statement: 'from readability import Document'.
ModuleNotFoundError: No module named 'lxml'
The 'lxml' dependency required by 'readability-lxml' is not installed.
fix
Install the 'lxml' package using pip: 'pip install lxml'.
AttributeError: module 'readability' has no attribute 'Document'
The 'readability' module does not contain a 'Document' attribute, possibly due to an incorrect import or installation issue.
fix
Verify the installation of 'readability-lxml' and use the correct import statement: 'from readability import Document'.
cannot import name 'Document' from 'readability'
This specific import error happens when the Python interpreter finds a 'readability' module but cannot find the 'Document' class within it. This is frequently due to a name collision with other libraries (like 'py-readability-metrics') that also expose a 'readability' module, or a local script named 'readability.py'.
fix
First, ensure `readability-lxml` is installed. If the problem persists and you have `py-readability-metrics` installed, it's recommended to use separate virtual environments for each library to prevent import conflicts. Also, check for and rename any local files named `readability.py`.
Upgrade
Version history
0.9latest on PyPI · released Aug 27, 2026
Audit
Dependencies
chardetrequiredUsed for character encoding detection.
cssselectrequiredUsed for CSS selector support in parsing.
lxmlrequiredCore dependency for HTML parsing and DOM manipulation.
lxml-html-cleanrequiredUsed for cleaning HTML.
Agent activity
22 hits · last 30 days
node
18
OpenAI (training)
1
Resources
readability-lxml — pip install readability-lxml · libregistry