Registry / data / polyleven

polyleven

JSON →
library0.11.0pypypi✓ verified 25d ago

Polyleven is a hyper-fast Python library for computing Levenshtein distance, implemented in C for optimal performance. It is designed to be efficient for comparing both short and long string inputs, is stand-alone with no external Python dependencies, and is distributed under the MIT License. The current version is 0.11.0, released on February 9, 2026, indicating an active release cadence.

pip install polyleven
INSTALL
IMPORT
SIG · POLYLEVEN
P
polyleven
datapythonv0.11.0
Install
1.7s 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 v0.11.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.7s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

levenshtein
from polyleven import levenshtein

This quickstart demonstrates how to import the `levenshtein` function and use it to calculate the Levenshtein distance between two strings. It also shows how to leverage the optional `max_threshold` argument to improve performance, especially when only interested in distances below a certain value.

from polyleven import levenshtein # Calculate Levenshtein distance between two strings distance1 = levenshtein('kitten', 'sitting') print(f"Distance between 'kitten' and 'sitting': {distance1}") # Calculate Levenshtein distance with a maximum threshold for efficiency # If the actual distance exceeds the threshold, the threshold + 1 is returned. distance2 = levenshtein('apple', 'aple', 1) # Actual distance is 1 print(f"Distance between 'apple' and 'aple' with max_threshold=1: {distance2}") distance3 = levenshtein('banana', 'orange', 2) # Actual distance is higher than 2 print(f"Distance between 'banana' and 'orange' with max_threshold=2: {distance3}") assert distance1 == 3 assert distance2 == 1 assert distance3 == 3 # Returns threshold + 1 because actual distance > threshold
Debug
Known issues
gotchaFor optimal performance, especially with long strings or when only interested in small distances, provide an integer `k` as the third argument to the `levenshtein()` function. This `max_threshold` limits the maximum distance computed, making the operation significantly more efficient. If the true distance exceeds `k`, the function returns `k + 1`.
fix
Call `levenshtein('string1', 'string2', k=max_threshold)` where `max_threshold` is the maximum relevant distance. For example, `levenshtein('abcde', 'xxxxx', 2)` would return `3` as the actual distance (5) is greater than the threshold (2).
affects: All versions
gotchaThe license for Polyleven changed from Public Domain to MIT License starting from version 0.7. Users of older versions relying on Public Domain terms should be aware of this change.
fix
Verify the license (MIT for v0.7+) to ensure compatibility with your project's licensing requirements. If strict adherence to Public Domain is necessary, ensure usage of versions prior to 0.7.
affects: Prior to 0.7 (Public Domain); 0.7 and later (MIT License)
gotchaWhile the `max_threshold` argument generally improves performance, the speed boost is most noticeable when the threshold `k` is small, typically less than 3. Larger thresholds still offer some benefit but diminish as `k` approaches the full string length.
fix
When designing for maximum performance and a small distance is expected or acceptable, prioritize using a `max_threshold` value of 1 or 2.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'polyleven'
The 'polyleven' library is not installed in your current Python environment or the Python interpreter cannot find it.
fix
Install the library using pip: `pip install polyleven`
ImportError: cannot open shared object file: No such file or directory
This error typically occurs when the C extension part of 'polyleven' cannot be loaded, often due to missing system dependencies (like C/C++ runtime libraries) or an incomplete/corrupted installation, especially on Linux systems.
fix
Ensure your system has the necessary build tools and C/C++ runtime libraries. Try reinstalling 'polyleven' in a clean environment: `pip uninstall polyleven` then `pip install polyleven`. If on Linux, ensure `gcc` and `g++` are installed, and consider updating system libraries.
AttributeError: module 'polyleven' has no attribute 'levenshteinn'
You are attempting to call a function or access an attribute named 'levenshteinn' which does not exist in the 'polyleven' module. This is likely a typo.
fix
The correct function name for calculating Levenshtein distance is `levenshtein`. Correct your code to `from polyleven import levenshtein` and use `levenshtein(str1, str2)`.
TypeError: levenshtein() takes at most 3 arguments (4 given)
The `levenshtein` function was called with more arguments than it expects. It accepts two strings and an optional integer threshold argument.
fix
Review your function call and provide only two string arguments (the strings to compare) and an optional third integer argument for the maximum distance threshold, e.g., `levenshtein('string1', 'string2')` or `levenshtein('string1', 'string2', max_distance_int)`.
Upgrade
Version history
0.11.0latest on PyPI · released Feb 9, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
polyleven — pip install polyleven · libregistry