{"id":1276,"library":"python-levenshtein","title":"python-levenshtein","description":"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.","status":"active","version":"0.27.3","language":"python","source_language":"en","source_url":"https://github.com/rapidfuzz/python-Levenshtein.git","tags":["levenshtein","edit distance","string similarity","fuzzy matching","nlp","c-extension"],"install":[{"cmd":"pip install python-levenshtein","lang":"bash","label":"Install `python-levenshtein` compatibility package"}],"dependencies":[{"reason":"Runtime environment","package":"python","optional":false},{"reason":"The underlying, actively developed package that `python-levenshtein` now wraps for compatibility.","package":"levenshtein","optional":false}],"imports":[{"note":"The installed module is always named `Levenshtein` regardless of the PyPI package name (`python-levenshtein` or `levenshtein`).","wrong":"from python_levenshtein import distance","symbol":"Levenshtein","correct":"import Levenshtein"}],"quickstart":{"code":"import Levenshtein\n\nstr1 = \"kitten\"\nstr2 = \"sitting\"\n\n# Calculate Levenshtein distance\ndistance = Levenshtein.distance(str1, str2)\nprint(f\"Levenshtein distance between '{str1}' and '{str2}': {distance}\")\n\n# Calculate similarity ratio\nratio = Levenshtein.ratio(str1, str2)\nprint(f\"Similarity ratio between '{str1}' and '{str2}': {ratio:.2f}\")\n\n# Example with different strings\nstr3 = \"hello\"\nstr4 = \"hallo\"\ndistance2 = Levenshtein.distance(str3, str4)\nratio2 = Levenshtein.ratio(str3, str4)\nprint(f\"\\nLevenshtein distance between '{str3}' and '{str4}': {distance2}\")\nprint(f\"Similarity ratio between '{str3}' and '{str4}': {ratio2:.2f}\")","lang":"python","description":"Calculate the Levenshtein distance (minimum number of single-character edits) and a similarity ratio between two strings."},"warnings":[{"fix":"Prefer `pip install levenshtein` for new projects. If using `python-levenshtein`, be aware it acts as a shim.","message":"The 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.","severity":"breaking","affected_versions":"All versions post-renaming (roughly 0.20.0 onwards for `levenshtein` and 0.25.0 onwards for `python-levenshtein`)."},{"fix":"Review your project's licensing compatibility. For less restrictive alternatives, consider `rapidfuzz` (MIT license) or `pylev` (New BSD license).","message":"The 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your project uses Python 3.10 or newer to maintain compatibility with the latest versions of the library.","message":"Recent 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.","severity":"breaking","affected_versions":"0.26.0+"},{"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.","message":"While `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).","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'0.27.3':57 'activ':41 'c':10,81 'c-extens':80 'cadenc':71 'compat':64 'comput':18 'continu':58 'distanc':21,24,74 'edit':20,73 'extens':11,82 'function':16 'fuzzi':77 'high':14 'levenshtein':3,6,23,38,53,72 'like':22 'maintain':42,67 'match':78 'metric':29 'modul':12 'name':45 'nlp':79 'optim':15 'packag':32,55 'posit':69 'provid':13 'pypi':54 'python':2,5,9,52 'python-levenshtein':1,4,51 'rapidfuzz':48 'ratio':26 'relat':28 'releas':70 'renam':36 'similar':25,76 'string':19,75 'team':49 'updat':61 'version':56 'wrapper':65","created_at":"2026-04-06T16:57:40.354649+00:00","updated_at":"2026-04-16T20:23:34.280390+00:00","problems":[{"fix":"import levenshtein","cause":"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'.","error":"ModuleNotFoundError: No module named 'Levenshtein'"},{"fix":"Install Microsoft C++ Build Tools, typically via the 'Desktop development with C++' workload in the Visual Studio Installer.","cause":"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.","error":"error: Microsoft Visual C++ 14.0 or greater is required."},{"fix":"import levenshtein\n# Then use functions like: levenshtein.distance('string1', 'string2')","cause":"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.","error":"ImportError: cannot import name 'distance' from 'levenshtein'"},{"fix":"import levenshtein","cause":"While the PyPI package is `python-levenshtein`, the actual Python module installed and intended for import is named `levenshtein`.","error":"ModuleNotFoundError: No module named 'python_levenshtein'"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.27.4","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/rapidfuzz/python-Levenshtein","docs":"https://rapidfuzz.github.io/Levenshtein/","changelog":"https://github.com/rapidfuzz/python-Levenshtein/blob/main/CHANGELOG.rst","pypi":"https://pypi.org/project/python-levenshtein/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["data"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-27","next_check":"2026-07-28","install_tag":"verified"}}