lev
lev is an extremely fast Python library for the Levenshtein distance and similarity ratio, written in Rust. 🦀
Installation
or if you prefer slow:
Wheels are available for Python 3.10 through 3.15, including free-threaded builds (PEP 703), on Linux, macOS, and Windows.
Usage
# 3
# 2
# 1
# 0.615...
# 0.0
# 1.0
See the API Reference for details.
Rust
lev is also published as the lev-rs crate:
assert_eq!;
assert_eq!;
The crate requires Rust 1.91 or newer. See docs.rs for details.
Benchmarks
lev is compared against the fastest Levenshtein libraries for Python:
rapidfuzz,
polyleven,
editdistance, and
edlib.
Each plot shows the total time for 1,000 calls (lower is better).
Plots were generated by GitHub Actions on Ubuntu 24.04 with Python 3.13. Reproduce them locally with
uv run scripts/benchmark.py.
ASCII
Latin-1
CJK
Emoji
Realistic Text
A short customer support message with a few natural typos.
Benchmark Scripts
Reproduce benchmarks locally using the provided scripts:
# Compare against other libraries:
# Benchmark scaling across string lengths:
# Benchmark speedup across released versions:
Contact
Open an issue or email github@markusbilz.com.