Registry / data / editdistpy

editdistpy

JSON →
library0.4.0pypypi✓ verified 23d ago

editdistpy (version 0.2.0) provides fast implementations of the Levenshtein and Damerau Optimal String Alignment (OSA) edit distance algorithms. Written in Cython/C++, it offers significant speed improvements for string comparison tasks. The library is actively maintained, with releases made periodically, the latest major version (0.2.0) released in February 2026.

pip install editdistpy
INSTALL
IMPORT
SIG · EDITDISTPY
E
editdistpy
datapythonv0.4.0
Install
1.6s avg
Import
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 18.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.000s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

levenshtein
from editdistpy import levenshtein
damerau_osa
from editdistpy import damerau_osa

This quickstart demonstrates how to calculate both Levenshtein and Damerau Optimal String Alignment (OSA) distances using `editdistpy`. It also highlights the use of `max_distance` for performance optimization, which returns -1 if the actual distance exceeds the specified maximum.

import sys from editdistpy import levenshtein, damerau_osa string_1 = "flintstone" string_2 = "hanson" # Levenshtein distance max_dist_lev = 2 lev_dist_bounded = levenshtein.distance(string_1, string_2, max_dist_lev) print(f"Levenshtein (max_distance={max_dist_lev}): {lev_dist_bounded}") # Expected: -1 lev_dist_full = levenshtein.distance(string_1, string_2, sys.maxsize) print(f"Levenshtein (full): {lev_dist_full}") # Expected: 6 # Damerau Optimal String Alignment (OSA) distance max_dist_osa = 2 osa_dist_bounded = damerau_osa.distance(string_1, string_2, max_dist_osa) print(f"Damerau OSA (max_distance={max_dist_osa}): {osa_dist_bounded}") # Expected: -1 osa_dist_full = damerau_osa.distance(string_1, string_2, sys.maxsize) print(f"Damerau OSA (full): {osa_dist_full}") # Expected: 6
Debug
Known issues
breakingSupport for Python 3.8 was officially dropped in version 0.1.6. Users on Python 3.8 or older must upgrade their Python environment to Python 3.9 or newer to use versions >= 0.1.6.
fix
Upgrade Python to version 3.9 or higher.
affects: >=0.1.6
gotchaWhen `max_distance` is provided to the `distance` method, it will return `-1` if the calculated edit distance exceeds this maximum. This is an intentional performance feature, not an error. To always get the full distance, pass `sys.maxsize` as `max_distance`.
fix
Handle the `-1` return value appropriately, or explicitly pass `sys.maxsize` for an unbounded calculation.
affects: All versions
gotchaThe `damerau_osa` module implements the Damerau Optimal String Alignment (OSA) distance, which is a restricted form of the Damerau-Levenshtein distance. OSA imposes a constraint that no substring may be edited more than once, meaning it does not always satisfy the triangle inequality and might return a different distance in certain cases compared to a full Damerau-Levenshtein implementation.
fix
Be aware of the distinction between Damerau OSA and the unrestricted Damerau-Levenshtein distance, and ensure it aligns with your specific use case. For typical typo correction, OSA is usually sufficient.
affects: All versions
deprecatedIn versions prior to 0.1.3, the library might not correctly handle distance calculations when one of the input strings is `None` or when `max_distance` is set to `0`. These issues were fixed in version 0.1.3.
fix
Upgrade to version 0.1.3 or later to ensure robust handling of `None` inputs and `max_distance=0`.
affects: <0.1.3
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'editdistpy'
The 'editdistpy' package is not installed in the Python environment being used, or the environment is not correctly activated.
fix
Install the package using pip: `pip install editdistpy` or `pip install -U editdistpy` to upgrade to the latest version. Ensure you are installing it in the correct Python environment (e.g., a virtual environment).
ERROR: Failed building wheel for editdistpy
This error typically occurs on Windows or other systems when the necessary C++ build tools (like Microsoft Visual C++ Build Tools) are not installed, as `editdistpy` is a Cython/C++ extension and requires compilation during installation if a pre-built wheel is not available for your specific Python version and operating system.
fix
On Windows, install 'Microsoft Visual C++ Build Tools'. For other operating systems, ensure you have a C/C++ compiler installed (e.g., `build-essential` on Debian/Ubuntu, or Xcode Command Line Tools on macOS).
AttributeError: module 'editdistpy' has no attribute 'levenshtein'
Users attempting to access `levenshtein.distance` or `damerau_osa.distance` directly from the top-level `editdistpy` module without explicitly importing the `levenshtein` or `damerau_osa` submodules.
fix
Import the specific edit distance algorithm (e.g., `levenshtein` or `damerau_osa`) from the `editdistpy` package: `from editdistpy import levenshtein` then use `levenshtein.distance(str1, str2)`.
Python version compatibility issues during installation or import.
Versions of `editdistpy` (e.g., 0.1.6 and later, including 0.2.0) dropped support for older Python versions like 3.8. Attempting to install or use the library with an incompatible Python interpreter will lead to installation failures or import errors.
fix
Upgrade your Python environment to version 3.9 or newer to be compatible with `editdistpy` version 0.2.0.
Upgrade
Version history
0.4.0latest on PyPI · released Jul 12, 2026
Audit
Dependencies
packagingrequiredAdded as a requirement in v0.2.0 for improved build and packaging robustness, particularly for wheel generation.
Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
1
Resources
editdistpy — pip install editdistpy · libregistry