{"id":5205,"library":"editdistpy","title":"editdistpy","description":"editdistpy (version 0.2.0) provides fast implementations of the Levenshtein and Damerau Optimal String Alignment (OSA) edit distance algorithms. Written in Cython/C++, it offers significant speed improvements for string comparison tasks. The library is actively maintained, with releases made periodically, the latest major version (0.2.0) released in February 2026.","status":"active","version":"0.2.0","language":"en","source_language":"en","source_url":"https://github.com/mammothb/editdistpy","tags":["string-comparison","edit-distance","levenshtein","damerau-osa","cython","performance"],"install":[{"cmd":"pip install editdistpy","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Added as a requirement in v0.2.0 for improved build and packaging robustness, particularly for wheel generation.","package":"packaging","optional":false}],"imports":[{"symbol":"levenshtein","correct":"from editdistpy import levenshtein"},{"symbol":"damerau_osa","correct":"from editdistpy import damerau_osa"}],"quickstart":{"code":"import sys\nfrom editdistpy import levenshtein, damerau_osa\n\nstring_1 = \"flintstone\"\nstring_2 = \"hanson\"\n\n# Levenshtein distance\nmax_dist_lev = 2\nlev_dist_bounded = levenshtein.distance(string_1, string_2, max_dist_lev)\nprint(f\"Levenshtein (max_distance={max_dist_lev}): {lev_dist_bounded}\") # Expected: -1\n\nlev_dist_full = levenshtein.distance(string_1, string_2, sys.maxsize)\nprint(f\"Levenshtein (full): {lev_dist_full}\") # Expected: 6\n\n# Damerau Optimal String Alignment (OSA) distance\nmax_dist_osa = 2\nosa_dist_bounded = damerau_osa.distance(string_1, string_2, max_dist_osa)\nprint(f\"Damerau OSA (max_distance={max_dist_osa}): {osa_dist_bounded}\") # Expected: -1\n\nosa_dist_full = damerau_osa.distance(string_1, string_2, sys.maxsize)\nprint(f\"Damerau OSA (full): {osa_dist_full}\") # Expected: 6","lang":"python","description":"This quickstart demonstrates how to calculate both Levenshtein and Damerau Optimal String Alignment (OSA) distances using `editdistpy`. It also highlights the use of `max_distance` for performance optimization, which returns -1 if the actual distance exceeds the specified maximum."},"warnings":[{"fix":"Upgrade Python to version 3.9 or higher.","message":"Support for Python 3.8 was officially dropped in version 0.1.6. Users on Python 3.8 or older must upgrade their Python environment to Python 3.9 or newer to use versions >= 0.1.6.","severity":"breaking","affected_versions":">=0.1.6"},{"fix":"Handle the `-1` return value appropriately, or explicitly pass `sys.maxsize` for an unbounded calculation.","message":"When `max_distance` is provided to the `distance` method, it will return `-1` if the calculated edit distance exceeds this maximum. This is an intentional performance feature, not an error. To always get the full distance, pass `sys.maxsize` as `max_distance`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Be aware of the distinction between Damerau OSA and the unrestricted Damerau-Levenshtein distance, and ensure it aligns with your specific use case. For typical typo correction, OSA is usually sufficient.","message":"The `damerau_osa` module implements the Damerau Optimal String Alignment (OSA) distance, which is a restricted form of the Damerau-Levenshtein distance. OSA imposes a constraint that no substring may be edited more than once, meaning it does not always satisfy the triangle inequality and might return a different distance in certain cases compared to a full Damerau-Levenshtein implementation.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade to version 0.1.3 or later to ensure robust handling of `None` inputs and `max_distance=0`.","message":"In versions prior to 0.1.3, the library might not correctly handle distance calculations when one of the input strings is `None` or when `max_distance` is set to `0`. These issues were fixed in version 0.1.3.","severity":"deprecated","affected_versions":"<0.1.3"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}