Registry / data / python-levenshtein

python-levenshtein

JSON →
library0.27.4pypypi✓ verified 27d ago

python-levenshtein is a Python C extension module providing highly optimized functions for computing string edit distances (like Levenshtein distance), similarity ratios, and related metrics. While the package itself has been renamed to `levenshtein` and is actively maintained under that name by the RapidFuzz team, the `python-levenshtein` PyPI package (version 0.27.3) continues to be updated as a compatibility wrapper. It maintains a positive release cadence.

pip install python-levenshtein
INSTALL
IMPORT
SIG · PYTHON-LEVENSHTEIN
P
python-levenshtein
datapythonv0.27.4
Install
2.7s avg
Import
35ms
Disk
32MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.27.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.036s · 38.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.7s · import 0.034s · 31MB
32MB installed
● package 32MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Levenshtein
import Levenshtein
from python_levenshtein import distance
The installed module is always named `Levenshtein` regardless of the PyPI package name (`python-levenshtein` or `levenshtein`).

Calculate the Levenshtein distance (minimum number of single-character edits) and a similarity ratio between two strings.

import Levenshtein str1 = "kitten" str2 = "sitting" # Calculate Levenshtein distance distance = Levenshtein.distance(str1, str2) print(f"Levenshtein distance between '{str1}' and '{str2}': {distance}") # Calculate similarity ratio ratio = Levenshtein.ratio(str1, str2) print(f"Similarity ratio between '{str1}' and '{str2}': {ratio:.2f}") # Example with different strings str3 = "hello" str4 = "hallo" distance2 = Levenshtein.distance(str3, str4) ratio2 = Levenshtein.ratio(str3, str4) print(f"\nLevenshtein distance between '{str3}' and '{str4}': {distance2}") print(f"Similarity ratio between '{str3}' and '{str4}': {ratio2:.2f}")
Debug
Known issues
breakingThe primary development for this library now occurs under the `levenshtein` PyPI package. `python-levenshtein` is maintained as a compatibility wrapper. It's recommended to install `levenshtein` directly for new projects and for accessing the latest features and fixes, though `pip install python-levenshtein` will still work by installing `levenshtein` as a dependency.
fix
Prefer `pip install levenshtein` for new projects. If using `python-levenshtein`, be aware it acts as a shim.
affects: All versions post-renaming (roughly 0.20.0 onwards for `levenshtein` and 0.25.0 onwards for `python-levenshtein`).
gotchaThe library is licensed under GPL-2.0. This copyleft license can be restrictive for projects with different licensing requirements, as it may necessitate that derivative works also be licensed under GPL.
fix
Review your project's licensing compatibility. For less restrictive alternatives, consider `rapidfuzz` (MIT license) or `pylev` (New BSD license).
affects: All versions
breakingRecent versions of the underlying `levenshtein` library (which `python-levenshtein` now wraps) have dropped support for older Python versions. For example, version 0.26.0 dropped support for Python 3.8, and 0.27.0 requires Python 3.10 or later.
fix
Ensure your project uses Python 3.10 or newer to maintain compatibility with the latest versions of the library.
affects: 0.26.0+
gotchaWhile `python-levenshtein` (and `levenshtein`) is highly optimized due to its C extension, for extensive fuzzy matching, especially with large datasets or when a wider array of string similarity algorithms (e.g., Jaro-Winkler, token-based matching) is needed, the `rapidfuzz` library is often a more modern and performant alternative. `rapidfuzz` also offers more flexible licensing (MIT).
fix
For new projects or performance-critical applications, evaluate `rapidfuzz` (`pip install rapidfuzz`) as a potential alternative. It offers a similar API for many functions.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'Levenshtein'
The old `python-Levenshtein` package (which used `import Levenshtein`) has been superseded; the current `python-levenshtein` PyPI package installs the `levenshtein` module, which should be imported with a lowercase 'l'.
fix
import levenshtein
error: Microsoft Visual C++ 14.0 or greater is required.
Installing Python packages with C extensions on Windows requires Microsoft Visual C++ Build Tools to compile the C source code if a pre-compiled wheel is not available or compatible.
fix
Install Microsoft C++ Build Tools, typically via the 'Desktop development with C++' workload in the Visual Studio Installer.
ImportError: cannot import name 'distance' from 'levenshtein'
The `levenshtein` module provides its functions directly at the top level, so specific functions are accessed as attributes of the main module rather than being imported individually.
fix
import levenshtein
# Then use functions like: levenshtein.distance('string1', 'string2')
ModuleNotFoundError: No module named 'python_levenshtein'
While the PyPI package is `python-levenshtein`, the actual Python module installed and intended for import is named `levenshtein`.
fix
import levenshtein
Upgrade
Version history
0.27.4latest on PyPI · released Aug 8, 2026
Audit
Dependencies
pythonrequiredRuntime environment
levenshteinrequiredThe underlying, actively developed package that `python-levenshtein` now wraps for compatibility.
Agent activity
21 hits · last 30 days
node
20
Resources
python-levenshtein — pip install python-levenshtein · libregistry