Improved Colored Diff

2.0.10 · active · verified Thu Apr 09

icdiff is a Python library and command-line utility for displaying diffs with improved colorization, making it easier to read changes side-by-side. It aims to be a more user-friendly alternative to traditional `diff` output. The current version is 2.0.10, and it maintains a fairly active release cadence with updates typically every few months.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `ConsoleDiff` to generate a colored, side-by-side diff between two lists of strings. It configures the diff for a specific column width, includes line numbers, and sets custom file labels for the header.

from icdiff import ConsoleDiff

old_text = [
    "line 1: hello world",
    "line 2: foo bar",
    "line 3: baz qux"
]

new_text = [
    "line 1: hello earth",
    "line 2: foo baz",
    "line 3: baz qux",
    "line 4: new line"
]

differ = ConsoleDiff(
    cols=80,  # Specify number of columns for display
    line_numbers=True, # Show line numbers
    color=True # Enable color output
)

diff_lines = differ.make_table(
    old_text,
    new_text,
    fromfile='old_version.txt',
    tofile='new_version.txt',
    context=True # Show context lines
)

for line in diff_lines:
    print(line)

view raw JSON →