The `levenshtein` Python C extension module provides highly optimized functions for fast computation of Levenshtein (edit) distance, string similarity, and other related metrics. It is currently at version 0.27.3 and maintains an active release cadence with regular updates to support newer Python versions.
pip install levenshteinVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to calculate the Levenshtein distance, the normalized similarity ratio, and retrieve the sequence of edit operations between two strings using the `levenshtein` library.
Update your `requirements.txt` and `pip install` commands to use `levenshtein`. If you were importing as `from Levenshtein import ...`, this import path remains correct for both package names.
Ensure your Python environment meets the minimum requirement, which is currently Python 3.10 or later for version 0.27.3.
Be aware of the underlying calculation for `ratio()`. If a different similarity metric or weighting is required, consider using `Levenshtein.distance()` with custom `weights` parameters (e.g., `weights=(1,1,1)` for equal costs) and calculating your own normalized ratio, or explore other libraries like `rapidfuzz` that offer various ratio algorithms.
Ensure the package is installed using `pip install levenshtein` and then import it as `import levenshtein` in your Python code. If you specifically need the old `python-Levenshtein` package, install it with `pip install python-Levenshtein` and then `import Levenshtein`.
On Windows, install 'Build Tools for Visual Studio' (e.g., Visual Studio 2022 Build Tools) with the 'Desktop development with C++' workload. On Debian/Ubuntu, run `sudo apt-get install build-essential python3-dev`. On Fedora/RHEL, use `sudo dnf install @development-tools python3-devel`. On macOS, install Xcode Command Line Tools with `xcode-select --install`.
Either call the function using the module prefix, like `levenshtein.distance(str1, str2)`, or import the function directly using `from levenshtein import distance`.
Ensure that both arguments passed to `levenshtein.distance()` are valid string (str) objects. If processing a collection of strings, iterate over them and pass individual string elements to the function.
No dependency data recorded yet.