{"id":5609,"library":"distance","title":"Distance","description":"The `distance` library provides utilities for comparing arbitrary sequences, implementing metrics such as Levenshtein, Hamming, Jaccard, and Sorensen distances. It offers both pure Python implementations and C extensions for performance. The library's last release was in 2013, indicating it is no longer actively maintained.","status":"abandoned","version":"0.1.3","language":"en","source_language":"en","source_url":"https://github.com/doukremt/distance","tags":["distance","levenshtein","hamming","jaccard","sorensen","sequence comparison"],"install":[{"cmd":"pip install Distance","lang":"bash","label":"Install stable version"},{"cmd":"pip install Distance --global-option=\"--with-c\"","lang":"bash","label":"Install with C extension (requires C compiler and Python headers)"}],"dependencies":[],"imports":[{"symbol":"levenshtein","correct":"import distance\ndistance.levenshtein('string1', 'string2')"},{"symbol":"hamming","correct":"import distance\ndistance.hamming('string1', 'string2')"},{"symbol":"jaccard","correct":"import distance\ndistance.jaccard('seq1', 'seq2')"},{"symbol":"sorensen","correct":"import distance\ndistance.sorensen('seq1', 'seq2')"}],"quickstart":{"code":"import distance\n\n# Levenshtein Distance\nword1 = \"kitten\"\nword2 = \"sitting\"\nlev_dist = distance.levenshtein(word1, word2)\nprint(f\"Levenshtein distance between '{word1}' and '{word2}': {lev_dist}\")\n\n# Hamming Distance (for sequences of equal length)\nseq1 = \"karolin\"\nseq2 = \"kathrin\"\nham_dist = distance.hamming(seq1, seq2)\nprint(f\"Hamming distance between '{seq1}' and '{seq2}': {ham_dist}\")\n\n# Jaccard Distance\nset1 = \"apple\"\nset2 = \"apply\"\njacc_dist = distance.jaccard(set1, set2)\nprint(f\"Jaccard distance between '{set1}' and '{set2}': {jacc_dist}\")","lang":"python","description":"Calculates Levenshtein, Hamming, and Jaccard distances between sequences using the primary functions provided by the library."},"warnings":[{"fix":"Consider using actively maintained alternatives such as `textdistance`, `python-Levenshtein` (now `Levenshtein`), `editdistance`, or `scipy.spatial.distance` for similar functionality, which offer better compatibility and performance with current Python environments.","message":"The `distance` library has not been updated since November 2013 (version 0.1.3). It is considered unmaintained, and may have compatibility issues or unaddressed bugs with modern Python versions (beyond Python 3.3, which it nominally supported) and newer system architectures. Other libraries like `textdistance` have explicitly removed support for 'distance' due to its unmaintained status.","severity":"breaking","affected_versions":"<=0.1.3"},{"fix":"If C extension installation fails, remove the `--global-option=\"--with-c\"` flag and use the pure Python implementation. For better performance with C extensions, consider modern libraries that are actively maintained and provide optimized C/Cython implementations (e.g., `Levenshtein` for string distances).","message":"Installing the optional C extension requires a C compiler and Python development headers to be present on your system. Without these, the `pip install` command with `--with-c` will fail. The benefit of the C extension for performance might be negligible or detrimental on modern Python versions due to potential inefficiencies in old C API usage.","severity":"gotcha","affected_versions":"<=0.1.3"},{"fix":"Thoroughly test distance calculations with diverse string inputs, especially those involving non-ASCII characters or complex Unicode, if you choose to use this library. Prefer modern libraries for robust Unicode support.","message":"The library's changelog from 2013 mentions switching 'back to using the to-be-deprecated Python unicode api' for Python 2.7+ compatibility and fixing 'variable interversions in (C) levenshtein which produced sometimes strange results'. This indicates potential historical issues with string handling, especially Unicode, which could resurface or behave unexpectedly in certain edge cases with modern Python 3.x string types.","severity":"gotcha","affected_versions":"<=0.1.3"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}