Skip to content

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:

uv add lev-rs

or if you prefer slow:

pip install lev-rs

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. Each string pair is exactly 100 characters long. Results represent the total wall time for 1,000 repetitions using Python's timeit. To reproduce, run uv run python scripts/benchmark.py.

ASCII

lev is significantly faster than the other libraries on 100-character ASCII strings.

ASCII benchmark – light ASCII benchmark – dark

Other Encodings

lev maintains its lead across all four CPython string-encoding kinds.

Latin-1

Latin-1 benchmark – light Latin-1 benchmark – dark

CJK

CJK benchmark – light CJK benchmark – dark

Emoji

Emoji benchmark – light Emoji benchmark – dark