https://github.com/uguudei/diffstrings
Show difference of strings in color
https://github.com/uguudei/diffstrings
beginners-friendly difflib hacktoberfest jupyter-color nlp python-colored-output python-console-color
Last synced: 12 days ago
JSON representation
Show difference of strings in color
- Host: GitHub
- URL: https://github.com/uguudei/diffstrings
- Owner: Uguudei
- License: mit
- Created: 2022-10-25T03:26:19.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-12-12T10:27:14.000Z (about 3 years ago)
- Last Synced: 2025-11-30T23:36:46.791Z (about 2 months ago)
- Topics: beginners-friendly, difflib, hacktoberfest, jupyter-color, nlp, python-colored-output, python-console-color
- Language: Python
- Homepage:
- Size: 33.2 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# diffstrings
[](https://github.com/Uguudei/diffstrings/actions/workflows/test.yml)
[](https://github.com/Uguudei/diffstrings/actions/workflows/publish.yml)
[](https://github.com/Uguudei/diffstrings/actions/workflows/publish-testpypi.yml)
[](https://pypi.org/project/diffstrings/)
[](https://pypi.org/project/diffstrings/)
[](https://github.com/Uguudei/diffstrings/blob/main/LICENSE)
[](https://github.com/psf/black)
[](https://pycqa.github.io/isort/)
Show difference of strings in color. It works on both terminal and ipython.
It extends difflib.SequenceMatcher class and provides a direct function too.
## Installation
```python
pip install diffstrings
```
## API
### Example Result

Color explanation:
- Green: to add
- Yellow: to replace. (Remove yellow colored then add with green colored strings)
- Red: to be removed
### Example texts
```bash
# Truth text to compare with
truth = """Lorem ipsum dolor sit amet,consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.f"""
# Supposedly wrong text to compare
predict = """Lorem furio dlfgor sit amet, consectetur apiscbgfing elit, sed do eiusmod tempor inciddfbunt ut labore et ddslore magna aliqua. Ut enim ad minim veniam, quis nostrud exercsfsation ullamco laboris assi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in volbcvbte velit esse cilldm doldsre eu fugiat nulla pafdgatur. Excepteur sint occaecat cupidatat non pident, sunt in culpa qui asafficia desert mollit anim id est lfdgarum."""
```
### Using class
```bash
from diffstrings import SequenceMatcher
s = SequenceMatcher(None, predict, truth, autojunk=False)
print(s.diff_strings())
print(s.diff_strings(True))
```
### Using function
```bash
from diffstrings import diff_strings
print(diff_strings(predict, truth))
print(diff_strings(predict, truth, show_change_on_seq2=True))
```