Editdistance
Editdistance is a Python library providing a fast, C++ and Cython-optimized implementation of the Levenshtein (edit) distance. It efficiently calculates the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one sequence into the other. The library is suitable for applications requiring high-performance string similarity calculations, such as fuzzy matching, data cleaning, and natural language processing. The current version is 0.8.1, but the project's GitHub repository has been archived, indicating it is no longer actively maintained by the owner.
Warnings
- breaking The GitHub repository for `editdistance` (roy-ht/editdistance) was archived by the owner on June 30, 2025, making it read-only. This indicates that the library is no longer under active development or maintenance by its original creator, and new features or bug fixes are unlikely to be released.
- gotcha A separate, pure-Python library named `edit_distance` (with an underscore) exists on PyPI. It has a different API, is typically slower, and is not the C++/Cython optimized `editdistance` library. Importing the wrong one is a common mistake.
- gotcha Versions prior to `0.8.0` might produce incorrect results for very long sequences (e.g., those with length > 640) due to a bug that was fixed in version `0.8.0`.
- gotcha As of November 2023, `editdistance` version 0.8.1 did not have compatible binary wheels for Python 3.13 (cp313), potentially leading to installation failures in strict wheelhouse environments or requiring a build from source, which might have additional dependencies.
Install
-
pip install editdistance
Imports
- eval
import editdistance editdistance.eval('string1', 'string2')
Quickstart
import editdistance
# Calculate edit distance between two strings
distance = editdistance.eval('kitten', 'sitting')
print(f"Edit distance between 'kitten' and 'sitting': {distance}")
# Works with any iterable of hashable objects (e.g., lists of words)
distance_list = editdistance.eval(['spam', 'egg'], ['spam', 'ham'])
print(f"Edit distance between ['spam', 'egg'] and ['spam', 'ham']: {distance_list}")