Compare text, and produce human-readable differences or deltas which look like track changes in Microsoft Word.
Maintained. Last release 3 months ago, commits in 4 of the last 26 weeks. Weaker on commit activity and release cadence.
pip install redlinesRedlines
Redlines compares two strings/text and produces structured output showing their differences. Changes are represented with strike-throughs and highlights, similar to Microsoft Word's track changes. The output includes detailed change information, positions, and statistics for programmatic use.
Supports multiple output formats: JSON (default, with structured change data and statistics), Markdown, HTML, and rich (terminal display).
Quick Start
# Install
pip install redlines
# CLI: Compare two texts (outputs JSON by default)
redlines "The quick brown fox jumps over the lazy dog." "The quick brown fox walks past the lazy dog."
# Python: Compare and get markdown
from redlines import Redlines
test = Redlines(
"The quick brown fox jumps over the lazy dog.",
"The quick brown fox walks past the lazy dog.",
markdown_style="none"
)
print(test.output_markdown)
# Output: The quick brown fox <del>jumps over </del><ins>walks past </ins>the lazy dog.
Supported: Python 3.10 - 3.14 (Python 3.8 and 3.9 support dropped)
Optional dependencies:
pip install redlines[pdf]for PDF file comparisonpip install redlines[nupunkt]for advanced sentence boundary detection (Python 3.11+, handles abbreviations, citations, URLs)pip install redlines[levenshtein]for additional statistics
Usage
Python API
The library contains one class: Redlines, which is used to compare text.
Basic comparison:
from redlines import Redlines
test = Redlines(
"The quick brown fox jumps over the lazy dog.",
"The quick brown fox walks past the lazy dog.",
markdown_style="none"
)
assert (
test.output_markdown
== "The quick brown fox <del>jumps over </del><ins>walks past </ins>the lazy dog."
)