Trafilatura supports seven output formats that cover a range of use cases — from simple plain-text pipelines to structured archival formats. The default is plain text (Documentation Index
Fetch the complete documentation index at: https://mintlify.com/adbar/trafilatura/llms.txt
Use this file to discover all available pages before exploring further.
"txt"). Select a format via the output_format parameter in Python or via a flag on the CLI.
TXT
Plain text. Default format. Optionally adds a YAML metadata header.
Markdown
Plain text with inline formatting (bold, italic, headings). Available from version 1.9.
JSON
Machine-readable JSON object. Includes all metadata fields when requested.
CSV
Tab-separated values. Fixed column order including URL, title, date, and body text.
HTML
Cleaned, minimal HTML. Available from version 1.11.
XML
Structured XML preserving document hierarchy, formatting, and links.
XML-TEI
TEI-compliant XML following the Text Encoding Initiative guidelines. Ideal for archival.
TXT (Plain Text)
The default output format. Extracts and returns the main text content as a clean, readable string. Comments are appended below the main text when present. What it includes: Main body text, optionally comments, and optionally a YAML front-matter metadata header (whenwith_metadata=True).
Example output:
with_metadata=True:
- Python
- CLI
Adding
include_formatting=True or include_links=True to a TXT extraction automatically switches the output to Markdown format to accommodate the extra structural elements.Markdown
Returns plain text with inline formatting preserved. Headings, bold, italic, and links are rendered as Markdown syntax. Available from version 1.9 onwards. Selecting Markdown automatically enables formatting — you do not need to passinclude_formatting=True separately.
What it includes: Main body text with Markdown-rendered formatting, headings, and (optionally) links.
Example output:
with_metadata=True, a YAML front-matter block is prepended (same as TXT format).
- Python
- CLI
JSON
Returns a JSON object. Without metadata, contains only"text" and "comments" fields. With with_metadata=True, all available metadata fields are included.
What it includes: Text body, comments, and (optionally) source, source-hostname, title, author, date, excerpt, categories, tags, fingerprint, language, image, pagetype, and more.
Example output (without metadata):
- Python
- CLI
The
include_formatting parameter has no effect on JSON output. Formatting markup is not included in the "text" field.CSV
Returns a tab-separated values (TSV) string with a fixed column order. All fields are present in every row; missing values are replaced with the stringnull.
Column order: url, id, fingerprint, hostname, title, image, date, text, comments, license, pagetype
Example output:
- Python
- CLI
As with TXT, combining CSV output with
--formatting or --links triggers Markdown output rather than plain CSV. To preserve the tabular structure, avoid those flags when using CSV format.HTML
Returns a cleaned, minimal HTML document containing the extracted main content. Metadata fields are emitted as<meta> tags inside a <head> element when with_metadata=True. Available from version 1.11 onwards.
What it includes: Main body as semantic HTML, optionally with a <head> block containing metadata <meta> tags.
Example output:
with_metadata=True:
- Python
- CLI
XML
Returns a structured XML document preserving heading hierarchy, paragraph divisions, formatting elements, links, and comments. Metadata is stored as attributes on the root<doc> element.
What it includes: <doc> root with metadata attributes, <main> element containing the body, <comments> element, and all preserved structural tags (<p>, <head>, <list>, <quote>, <code>, etc.).
Example output:
- Python
- CLI
XML-TEI (Text Encoding Initiative)
Returns a fully conformant TEI-XML document. Follows the guidelines of the Text Encoding Initiative and is suitable for archival, scholarly corpora, and digital humanities workflows. The output wraps extracted content in a standard<TEI> document tree with a <teiHeader> and a <text> body.
What it includes: Full TEI document with <teiHeader> (metadata), <text><body><div type="entry"> (main content), and <div type="comments"> (comment section).
Example output:
TEI Validation
Validate the output against the TEI standard using--validate-tei on the CLI or tei_validation=True in the extract() call. You can also call trafilatura.xml.validate_tei() directly on a parsed XML tree.
- Python
- CLI
Format Compatibility Notes
TXT/CSV + formatting or links → Markdown: Combining
"txt" or "csv" output with include_formatting=True or include_links=True automatically switches the output to Markdown format to accommodate the structural markup.Metadata in TXT/Markdown: When
with_metadata=True is used with "txt" or "markdown" output, a YAML front-matter block is prepended to the document. Fields included are: title, author, url, hostname, description, sitename, date, categories, tags, fingerprint, id, and license.include_formatting is ignored for JSON: The JSON "text" field always contains plain text. Formatting markup is not included regardless of the include_formatting setting.Images and links need XML formats: Image and link targets are only fully preserved in XML, XML-TEI, or HTML output. They may not be visible in TXT, Markdown, or CSV output.