pyxDamerauLevenshtein

raw JSON →
1.10.1 verified Mon Apr 27 auth: no python

High-performance Damerau-Levenshtein edit distance computation for Python, implemented in Cython. Currently at version 1.10.1, with wheels for CPython 3.9–3.14 on Linux, macOS, and Windows. Releases are stable and infrequent.

pip install pyxdameraulevenshtein
error ModuleNotFoundError: No module named 'pyxdameraulevenshtein'
cause Library not installed or wrong import name (common typo: pyxdameraulevenshtein vs pyxdamerau-levenshtein).
fix
Run: pip install pyxdameraulevenshtein
error TypeError: expected string or bytes-like object
cause Passed non-string (e.g., int, list) to distance function.
fix
Convert arguments to strings: str(arg1), str(arg2)
error ImportError: cannot import name 'damerau_levenshtein_distance' from 'pyxdameraulevenshtein'
cause Old library version (<1.0.0) may have different API. Current version 1.10.1 has this function.
fix
Upgrade: pip install --upgrade pyxdameraulevenshtein
gotcha The library uses Cython and ships prebuilt wheels for most platforms. On unsupported architectures (e.g., ARM Linux without manylinux), install from source requires a C compiler.
fix Install via pip; if source build fails, install a C compiler (gcc, clang) and ensure Python development headers are available.
gotcha Input strings must be of the same type (both str or both bytes). Mixing types may raise a TypeError.
fix Ensure both arguments are strings (or both bytes) before calling the distance functions.
gotcha The normalized distance function returns 0.0 for identical strings and 1.0 for completely different strings. It is not a symmetric normalized version of edit distance in the typical Levenshtein sense; it uses max length of the two strings as denominator.
fix Understand that normalized_damerau_levenshtein_distance computes distance / max(len(s1), len(s2)).

Compute Damerau-Levenshtein distance between two strings. Works for any hashable sequences (e.g., lists of tokens).

from pyxdameraulevenshtein import damerau_levenshtein_distance

string1 = 'hello'
string2 = 'hola'
dist = damerau_levenshtein_distance(string1, string2)
print(f"DL distance: {dist}")

# Normalized distance (0.0 to 1.0)
from pyxdameraulevenshtein import normalized_damerau_levenshtein_distance
norm_dist = normalized_damerau_levenshtein_distance(string1, string2)
print(f"Normalized DL distance: {norm_dist:.4f}")