{"id":3745,"library":"polyleven","title":"Polyleven","description":"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.","status":"active","version":"0.11.0","language":"en","source_language":"en","source_url":"https://github.com/fujimotos/polyleven","tags":["Levenshtein","distance","string similarity","edit distance","performance"],"install":[{"cmd":"pip install polyleven","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"symbol":"levenshtein","correct":"from polyleven import levenshtein"}],"quickstart":{"code":"from polyleven import levenshtein\n\n# Calculate Levenshtein distance between two strings\ndistance1 = levenshtein('kitten', 'sitting')\nprint(f\"Distance between 'kitten' and 'sitting': {distance1}\")\n\n# Calculate Levenshtein distance with a maximum threshold for efficiency\n# If the actual distance exceeds the threshold, the threshold + 1 is returned.\ndistance2 = levenshtein('apple', 'aple', 1) # Actual distance is 1\nprint(f\"Distance between 'apple' and 'aple' with max_threshold=1: {distance2}\")\n\ndistance3 = levenshtein('banana', 'orange', 2) # Actual distance is higher than 2\nprint(f\"Distance between 'banana' and 'orange' with max_threshold=2: {distance3}\")\n\nassert distance1 == 3\nassert distance2 == 1\nassert distance3 == 3 # Returns threshold + 1 because actual distance > threshold","lang":"python","description":"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."},"warnings":[{"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).","message":"For 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`.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":"Prior to 0.7 (Public Domain); 0.7 and later (MIT License)"},{"fix":"When designing for maximum performance and a small distance is expected or acceptable, prioritize using a `max_threshold` value of 1 or 2.","message":"While 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}