Compare text, and produce human-readable differences or deltas which look like track changes in Microsoft Word.
Project description
Redlines
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[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."
)
Multiple comparisons with one source:
from redlines import Redlines
test = Redlines("The quick brown fox jumps over the lazy dog.", markdown_style="none")
assert (
test.compare("The quick brown fox walks past the lazy dog.")
== "The quick brown fox <del>jumps over </del><ins>walks past </ins>the lazy dog."
)
assert (
test.compare("The quick brown fox jumps over the dog.")
== "The quick brown fox jumps over the <del>lazy </del>dog."
)
JSON output with structured data:
from redlines import Redlines
test = Redlines(
"The quick brown fox jumps over the lazy dog.",
"The quick brown fox walks past the lazy dog."
)
# Get JSON with changes, positions, and statistics
print(test.output_json(pretty=True))
CLI
Basic usage (outputs JSON by default):
redlines "old text" "new text"
redlines file1.txt file2.txt --pretty
Output formats:
redlines text "source" "test" # Rich terminal display
redlines markdown file1.txt file2.txt # Markdown output
redlines stats old.txt new.txt # Statistics only
Run redlines --help or redlines guide for the Agent Integration Guide. See also: redlines-textual.
Advanced Features
Custom Processors
Use NupunktProcessor for sentence-level tokenization with intelligent boundary detection:
from redlines import Redlines
from redlines.processor import NupunktProcessor
processor = NupunktProcessor()
test = Redlines("Dr. Smith said hello.", "Dr. Smith said hi.", processor=processor)
Use NupunktProcessor for: Legal/technical documents with abbreviations, URLs, citations, decimals Use WholeDocumentProcessor (default) for: Simple documents, speed-critical tasks (5-6x faster), paragraph-level granularity
See demo comparison for benchmarks.
For AI Agents & Automation
🤖 Using with AI coding agents? See the Agent Integration Guide for JSON schemas, automation patterns, error handling, and runnable examples.
Documentation & Resources
Full Documentation: https://houfu.github.io/redlines
Example Use Cases:
- View and mark changes in legislation: PLUS Explorer
- Visualise changes after ChatGPT transforms a text: ChatGPT Prompt Engineering for Developers Lesson 6
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file redlines-0.6.1.tar.gz.
File metadata
- Download URL: redlines-0.6.1.tar.gz
- Upload date:
- Size: 301.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5db4886b9a1b4d334d02ff7f03b8e702bbc40873ee222fe34b0054b4f55e836
|
|
| MD5 |
9388813214e2d1ae258ac10490103002
|
|
| BLAKE2b-256 |
07683b222458300a3aa0baf45dcc508ecaaa5dd5ab2d25e6d550699f392fdd3f
|
Provenance
The following attestation bundles were made for redlines-0.6.1.tar.gz:
Publisher:
python-publish.yml on houfu/redlines
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
redlines-0.6.1.tar.gz -
Subject digest:
e5db4886b9a1b4d334d02ff7f03b8e702bbc40873ee222fe34b0054b4f55e836 - Sigstore transparency entry: 721101442
- Sigstore integration time:
-
Permalink:
houfu/redlines@996a40d28843d2206fc01281eedc95a62db02854 -
Branch / Tag:
refs/tags/v0.6.1 - Owner: https://github.com/houfu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@996a40d28843d2206fc01281eedc95a62db02854 -
Trigger Event:
release
-
Statement type:
File details
Details for the file redlines-0.6.1-py3-none-any.whl.
File metadata
- Download URL: redlines-0.6.1-py3-none-any.whl
- Upload date:
- Size: 25.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
acf56b0f4f2c68b328b1c0890e5808fb34eaac89d199a0c7e4a5f4957c40c13a
|
|
| MD5 |
03207cc46bdbb125e24d4b082208c360
|
|
| BLAKE2b-256 |
7fa1fd575a81a363d8ef66997eaca21973ea98468ae6d8c8886f8d69472c3bbc
|
Provenance
The following attestation bundles were made for redlines-0.6.1-py3-none-any.whl:
Publisher:
python-publish.yml on houfu/redlines
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
redlines-0.6.1-py3-none-any.whl -
Subject digest:
acf56b0f4f2c68b328b1c0890e5808fb34eaac89d199a0c7e4a5f4957c40c13a - Sigstore transparency entry: 721101445
- Sigstore integration time:
-
Permalink:
houfu/redlines@996a40d28843d2206fc01281eedc95a62db02854 -
Branch / Tag:
refs/tags/v0.6.1 - Owner: https://github.com/houfu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@996a40d28843d2206fc01281eedc95a62db02854 -
Trigger Event:
release
-
Statement type: