Ukkonen

raw JSON →
1.1.0 verified Sat May 09 auth: no python

A Python implementation of bounded Levenshtein distance using the Ukkonen algorithm. Current version 1.1.0, requires Python >=3.10. Maintained by Anthony Sottile. Release cadence is low; no recent updates.

pip install ukkonen
error ModuleNotFoundError: No module named 'ukkonen'
cause Package not installed or installed in wrong environment.
fix
Run pip install ukkonen in the correct Python environment (3.10+).
error ImportError: cannot import name 'distance' from 'ukkonen'
cause Possible mismatch or corrupted installation.
fix
Reinstall with pip install --upgrade ukkonen.
gotcha The function returns -1 if the true distance exceeds max_distance, not the actual distance.
fix Check result >=0 to confirm distance is within bound.
gotcha Requires Python >=3.10. Installing on older versions will fail.
fix Ensure Python 3.10+ before installing.

Compute Levenshtein distance with a bound. Returns -1 if distance exceeds max_distance.

from ukkonen import distance

# Compute bounded Levenshtein distance
result = distance('kitten', 'sitting', max_distance=3)
print(result)  # Output: 3