Redlines

0.6.1 · active · verified Wed Apr 15

Redlines is a Python library that compares two strings or blocks of text, producing human-readable differences or 'deltas' similar to Microsoft Word's track changes. It provides structured output showing detailed change information, positions, and statistics, supporting various formats like JSON (default for CLI), Markdown, HTML, and rich terminal display. The current version is 0.6.1, and the project exhibits an active release cadence.

Warnings

Install

Imports

Quickstart

Instantiate the `Redlines` class with two strings to compare. The class provides methods like `output_markdown`, `output_json`, and `output_rich` for different output formats. The `compare` method can be used for subsequent comparisons against the initial 'old' text.

from redlines import Redlines

old_text = "The quick brown fox jumps over the lazy dog."
new_text = "The quick brown fox walks past the lazy cat."

# Create a Redlines object
comparator = Redlines(old_text, new_text)

# Get markdown output with <del>/<ins> tags
markdown_output = comparator.output_markdown
print(f"Markdown Output:\n{markdown_output}\n")

# Get JSON output (structured data)
json_output = comparator.output_json()
print(f"JSON Output:\n{json_output}\n")

# Example of using the compare method for multiple comparisons
alternate_new_text = "The quick brown fox sleeps near the lazy dog."
compare_output = comparator.compare(alternate_new_text)
print(f"Comparison with alternate text:\n{compare_output}")

view raw JSON →