CyDifflib
raw JSON → 1.2.0 verified Fri May 01 auth: no python
A fast Cython-powered implementation of Python's difflib algorithms (SequenceMatcher, unified_diff, etc.). Current version: 1.2.0. Released irregularly, maintained by the RapidFuzz project. Requires Python >=3.9.
pip install cydifflib Common errors
error ImportError: cannot import name 'SequenceMatcher' from 'cydifflib' ↓
cause The module is not installed or you're using a very old version that had a different API (pre-1.0).
fix
Run 'pip install --upgrade cydifflib' to get the latest version.
error AttributeError: 'SequenceMatcher' object has no attribute 'get_grouped_opcodes' ↓
cause CyDifflib's SequenceMatcher does not implement all methods from stdlib difflib.
fix
Use difflib.SequenceMatcher if you need get_grouped_opcodes or other missing methods.
error TypeError: Expected str, got bytes ↓
cause CyDifflib expects string inputs, not bytes. It does not handle bytes automatically.
fix
Decode bytes to str before passing: e.g., a = my_bytes.decode('utf-8')
Warnings
gotcha CyDifflib's SequenceMatcher is NOT a drop-in replacement for difflib.SequenceMatcher. It has fewer methods (e.g., no get_grouped_opcodes, real_quick_ratio) and behavior may differ slightly. ↓
fix Check the README for supported features. If you need full compatibility, use difflib instead.
gotcha The library may fail to compile from source if you have an incompatible Cython version or missing build tools. Pre-built wheels are available for most platforms, but not all. ↓
fix Install pre-built wheels from PyPI. If building from source, ensure Cython and a C compiler are installed. Consider using rapidfuzz as a fallback.
deprecated The cydifflib.SequenceMatcher object does not support autojunk parameter (ignored). This behavior is deprecated and will be removed in a future version. ↓
fix Avoid using autojunk parameter or expect it to be ignored. Future versions may raise an error.
Imports
- SequenceMatcher wrong
from difflib import SequenceMatchercorrectfrom cydifflib import SequenceMatcher - unified_diff wrong
from difflib import unified_diffcorrectfrom cydifflib import unified_diff
Quickstart
from cydifflib import SequenceMatcher
a = "hello world"
b = "hello earth"
sm = SequenceMatcher(None, a, b)
ratio = sm.ratio()
print(f"Similarity: {ratio:.2f}")