Install & Compatibility
Where this runs
tested against v2.2.0 · 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
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 2.174s · 79.7MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 4.7s · import 2.286s · 81MB
79MB installed
● package 79MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
fetch_url
✓ from trafilatura import fetch_url
extract
✓ from trafilatura import extract
bare_extraction
✓ from trafilatura import bare_extraction
✗ result = bare_extraction(html_content, as_dict=True)
`as_dict` argument is deprecated; `bare_extraction()` now returns a `Document` object. Use `.as_dict()` method on the returned object instead.
Document
✓ from trafilatura.settings import Document
Returned by `bare_extraction()`, provides an interface to extracted data including `.as_dict()` method.
This quickstart demonstrates how to fetch a web page and extract its main text content using `trafilatura`. It includes a basic extraction to plain text and an example of extracting structured JSON output with metadata.
from trafilatura import fetch_url, extract
import os
# Example URL from GitHub blog
url = 'https://github.blog/2019-03-29-leader-spotlight-erin-spiceland/'
# In a production setting, you might fetch a URL from a variable or a list
# For this example, we use a fixed public URL.
print(f"Fetching URL: {url}")
downloaded_html = fetch_url(url)
if downloaded_html:
print("Content successfully downloaded. Extracting...")
# Extract main content and comments as plain text by default
extracted_text = extract(downloaded_html)
if extracted_text:
print("--- Extracted Text (first 500 chars) ---")
print(extracted_text[:500])
print("...")
# Example of custom output: JSON with metadata
# Note: with_metadata=True is required for metadata inclusion since v1.11.0
print("\n--- Extracting as JSON with metadata ---")
extracted_json = extract(downloaded_html, output_format="json", with_metadata=True)
if extracted_json:
print(extracted_json[:500])
print("...")
else:
print("Failed to extract content as JSON.")
else:
print("No text extracted from the downloaded HTML.")
else:
print(f"Failed to download content from {url}")
trafilatura --version
Upgrade
Version history
2.2.0latest on PyPI · released Jul 31, 2026
Audit
Dependencies
certifirequiredRequired for secure connections.
charset_normalizer>=3.4.0requiredFor character encoding detection.
courlan>=1.3.2requiredUnderlying library for URL management and parsing.
htmldate>=1.9.2requiredFor robust date extraction from HTML.
justext>=3.0.1requiredUsed as a fallback for text extraction.
lxml>=5.3.0requiredCore dependency for HTML parsing and XPath operations.
urllib3<3,>=1.26requiredHTTP client for fetching web pages.
cchardetoptionalOptional: For faster character encoding detection.
langidoptionalOptional: For language detection.