Registry / serialization / pylev
library1.4.0pypypi✓ verified 25d ago

pylev is a pure Python implementation for calculating the Levenshtein distance between two strings, notable for its New BSD license unlike many other GPL-licensed alternatives. The current version is 1.4.0. It has an irregular release cadence, with updates addressing performance improvements and minor fixes.

pip install pylev
INSTALL
IMPORT
SIG · PYLEV
P
pylev
serializationpythonv1.4.0
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.4.0 · 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.000s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

levenshtein
import pylev distance = pylev.levenshtein('string1', 'string2')

Calculates the Levenshtein distance between two simple strings.

import pylev str1 = 'kitten' str2 = 'sitting' distance = pylev.levenshtein(str1, str2) print(f"Levenshtein distance between '{str1}' and '{str2}': {distance}")
Debug
Known issues
deprecatedIn v1.1.0, a much faster Levenshtein variant was introduced and became the default `pylev.levenshtein()`. The older, naive implementation was renamed to `pylev.classic_levenschtein()`. While aliases for backward-compatibility were added in v1.2.0, relying on the older, slower method or its original name is deprecated and should be avoided in new code.
fix
Always use `pylev.levenshtein()` for the optimized algorithm. If you explicitly need the naive implementation, use `pylev.classic_levenschtein()`.
affects: >=1.1.0
deprecatedIn v1.2.0, all incorrect spellings of 'Levenshtein' in method names were corrected. While older, misspelled method names were aliased for backward-compatibility, new code should exclusively use the correctly spelled versions to prevent potential future breakage or confusion.
fix
Ensure all calls to pylev functions use the correct spelling 'levenshtein' (without a 'c').
affects: >=1.2.0
gotcha`pylev.levenshtein()` computes the character-level Levenshtein distance between strings. If you intend to calculate word-level distance between sentences or phrases, you must first pre-process the strings into lists of words (e.g., using `str.split()`). Passing raw sentences will treat each character as an individual item.
fix
For word-level distance, convert strings to lists of words: `pylev.levenshtein(sentence1.split(), sentence2.split())`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pylev'
The `pylev` package has not been installed in the current Python environment or there is a typo in the import statement.
fix
Install the package using pip: `pip install pylev`
TypeError: 'module' object is not callable
The user is attempting to call the `pylev` module directly as a function instead of calling its `levenshtein` function.
fix
Access the `levenshtein` function within the `pylev` module: `pylev.levenshtein('string1', 'string2')`
ImportError: cannot import name 'some_function' from 'pylev'
The user is trying to import a function or submodule by a name (e.g., `distance`, `ratio`, `levenschtein` with a 'c') that is not directly exposed or does not exist in the `pylev` module's top level, or they are trying to import a deprecated name.
fix
Ensure you are importing the correct and currently supported function name, which is `levenshtein`: `from pylev import levenshtein` or `import pylev` and then `pylev.levenshtein(...)`
TypeError: object of type 'int' has no len()
The `pylev.levenshtein` function expects sequence-like arguments (e.g., strings or lists), but a non-sequence type like an integer was passed.
fix
Ensure both arguments passed to `pylev.levenshtein` are strings, lists, or other iterable sequences: `pylev.levenshtein('apple', 'aple')` or `pylev.levenshtein(['a', 'p', 'p', 'l', 'e'], ['a', 'p', 'l', 'e'])`
Upgrade
Version history
1.4.0latest on PyPI · released May 30, 2021
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
6
Resources
pylev — pip install pylev · libregistry