lev¶
Introduction¶
lev is an extremely fast Python library for the Levenshtein distance and similarity ratio, written in Rust. 🦀
Installation¶
Install the latest version from pypi:
or if you prefer slow:
Usage¶
import lev
lev.distance("kitten", "sitting") # 3
lev.distance("résumé", "resume") # 2
lev.distance("日本語", "日本") # 1
lev.ratio("kitten", "sitting") # 0.769...
lev.ratio("", "") # 1.0
For more details on the API see the API Reference.
Benchmarks¶
lev is benchmarked against the fastest Python Levenshtein libraries:
rapidfuzz,
editdistance, and
edlib. We excluded slower implementations like
pylev and python-Levenshtein.
Benchmarks
Benchmarks were run on an Apple Mac Mini M2 Pro (macOS 26.2) using Python 3.13.
The ASCII, Latin-1, CJK, and Emoji pairs are exactly 100 characters long;
the realistic-text pair is natural-length prose.
Results represent the total wall time for 1,000 repetitions using Python's timeit.
To reproduce, run uv run scripts/benchmark.py.
ASCII¶
lev is significantly faster than the other libraries on 100-character ASCII strings.
Other Encodings¶
lev maintains its lead across all four CPython string-encoding kinds.
Latin-1¶
CJK¶
Emoji¶
Realistic Text¶
This pair is a short customer support message with a handful of natural typos.