Metadata-Version: 2.4
Name: lev-rs
Version: 0.5.1
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Programming Language :: Python :: Free Threading :: 3 - Stable
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
License-File: LICENSE
Summary: An extremely fast Python library for the Levenshtein distance and similarity ratio, written in Rust 🦀.
Keywords: distance,levenshtein,strings
Author-email: Markus Bilz <github@markusbilz.com>
License-Expression: MIT
Requires-Python: >=3.10
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Bug Tracker, https://github.com/KarelZe/lev/issues
Project-URL: Homepage, https://github.com/KarelZe/lev

# lev

`lev` is an extremely fast Python library for the [Levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance) and similarity ratio, written in Rust. 🦀

## Installation

```bash
uv add lev-rs
```

or if you prefer slow:

```bash
pip install lev-rs
```

Wheels are available for Python 3.10+, including free-threaded builds, on Linux, macOS, and Windows.

## Usage

```python
import lev

lev.distance("kitten", "sitting")  # 3
lev.distance("résumé", "resume")  # 2
lev.distance("日本語", "日本")  # 1

lev.ratio("kitten", "sitting")  # 0.615...
lev.ratio("abc", "xyz")  # 0.0
lev.ratio("", "")  # 1.0
```

See the [API Reference](https://karelze.github.io/lev/api/) for details.

## Benchmarks

`lev` is compared against the fastest Levenshtein libraries for Python:
[rapidfuzz](https://github.com/rapidfuzz/RapidFuzz),
[polyleven](https://github.com/fujimotos/polyleven),
[editdistance](https://github.com/roy-ht/editdistance), and
[edlib](https://github.com/Martinsos/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`](https://github.com/KarelZe/lev/blob/main/scripts/benchmark.py).

### ASCII

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/KarelZe/lev/main/docs/assets/benchmark_ascii_dark.svg">
  <img alt="ASCII benchmark" src="https://raw.githubusercontent.com/KarelZe/lev/main/docs/assets/benchmark_ascii_light.svg">
</picture>

### Latin-1

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/KarelZe/lev/main/docs/assets/benchmark_latin_1_dark.svg">
  <img alt="Latin-1 benchmark" src="https://raw.githubusercontent.com/KarelZe/lev/main/docs/assets/benchmark_latin_1_light.svg">
</picture>

### CJK

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/KarelZe/lev/main/docs/assets/benchmark_cjk_dark.svg">
  <img alt="CJK benchmark" src="https://raw.githubusercontent.com/KarelZe/lev/main/docs/assets/benchmark_cjk_light.svg">
</picture>

### Emoji

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/KarelZe/lev/main/docs/assets/benchmark_emoji_dark.svg">
  <img alt="Emoji benchmark" src="https://raw.githubusercontent.com/KarelZe/lev/main/docs/assets/benchmark_emoji_light.svg">
</picture>

### Realistic Text

A short customer support message with a few natural typos.

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/KarelZe/lev/main/docs/assets/benchmark_realistic_dark.svg">
  <img alt="Realistic text benchmark" src="https://raw.githubusercontent.com/KarelZe/lev/main/docs/assets/benchmark_realistic_light.svg">
</picture>

## Contact

Open an issue or email `github@markusbilz.com`.

