Diffplus
raw JSON → 1.4.0 verified Sat May 09 auth: no python
Diffplus is a Python library for computing incremental and contextual diffs between two indented configurations (e.g., YAML, INI, or any indented text). Version 1.4.0, last updated in 2025. Release cadence is irregular (major versions every few months). It supports Python >=3.8 and is designed to produce structured diff output highlighting additions, deletions, and context.
pip install diffplus Common errors
error AttributeError: module 'diffplus' has no attribute 'diff_indented' ↓
cause Function renamed in v1.0.0.
fix
Use diff_texts instead: from diffplus import diff_texts
error TypeError: diff_texts() got an unexpected keyword argument 'context' ↓
cause Parameter name changed from 'context' to 'context_lines' in v1.0.0.
fix
Use context_lines instead: diff_texts(..., context_lines=2)
error ValueError: Input text is not properly indented ↓
cause Inconsistent indentation (e.g., mixed tabs and spaces) or empty input.
fix
Ensure both inputs use consistent indentation (spaces only) and are not empty.
Warnings
gotcha The library assumes input text has consistent indentation (spaces only). Mixing tabs and spaces may produce incorrect diffs. ↓
fix Preprocess inputs to replace tabs with spaces before calling diff_texts.
gotcha The 'context_lines' parameter can cause unexpected output if set too high. Default is 3; for large files, consider reducing to 1 or 0. ↓
fix Explicitly set context_lines for your use case, e.g., diff_texts(..., context_lines=1).
deprecated Function 'diff_indented' has been renamed to 'diff_texts' in v1.0.0. ↓
fix Use 'from diffplus import diff_texts' instead of 'from diffplus import diff_indented'.
Imports
- diff_texts
from diffplus import diff_texts - DiffResult wrong
from diffplus.models import DiffResultcorrectfrom diffplus import DiffResult
Quickstart
from diffplus import diff_texts
text_a = """
parent:
child1: value1
child2: value2
"""
text_b = """
parent:
child1: modified_value1
child3: value3
"""
diff_result = diff_texts(text_a, text_b, context_lines=2)
print(diff_result)
# Optional: access structured changes
for change in diff_result.changes:
print(change.line, change.type)