difflib compares sequences and emits formats recognized by review tools. unified_diff accepts lines with their endings preserved and creates a textual patch useful in logs, tests, and reports.

from difflib import unified_diff

before = "name=Ana\nstatus=pending\n".splitlines(keepends=True)
after = "name=Ana\nstatus=active\n".splitlines(keepends=True)

diff = unified_diff(before, after, fromfile="before", tofile="after")
print("".join(diff))

How to use it safely

Normalize only what the business rule considers irrelevant; removing whitespace or case can hide real changes. SequenceMatcher is not a linguistic distance algorithm and may be costly on large inputs. Set limits for external data.

To strengthen the foundation, read Python collections guide and type hints guide.

The official Python documentation, accessed July 22, 2026, describes the API, edge cases, and version compatibility.