Registry / data / distance

distance

JSON →
library0.1.3pypypi✓ verified 23d ago

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.

pip install Distance
INSTALL
IMPORT
SIG · DISTANCE
D
distance
datapythonv0.1.3
Install
3.9s avg
Import
Disk
12MB
Pass rate
2/ 10
Env Coverage2 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.3 · 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
glibc
py 3.10
1/2 runs
1/2 runs
py 3.11
1/2 runs
1/2 runs
py 3.12
✓ —
✓ 3.9s
py 3.13
1/2 runs
1/2 runs
py 3.9
1/2 runs
1/2 runs
12MB installed
● package 12MB
Code
Verified usage

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

levenshtein
import distance distance.levenshtein('string1', 'string2')
hamming
import distance distance.hamming('string1', 'string2')
jaccard
import distance distance.jaccard('seq1', 'seq2')
sorensen
import distance distance.sorensen('seq1', 'seq2')

Calculates Levenshtein, Hamming, and Jaccard distances between sequences using the primary functions provided by the library.

import distance # Levenshtein Distance word1 = "kitten" word2 = "sitting" lev_dist = distance.levenshtein(word1, word2) print(f"Levenshtein distance between '{word1}' and '{word2}': {lev_dist}") # Hamming Distance (for sequences of equal length) seq1 = "karolin" seq2 = "kathrin" ham_dist = distance.hamming(seq1, seq2) print(f"Hamming distance between '{seq1}' and '{seq2}': {ham_dist}") # Jaccard Distance set1 = "apple" set2 = "apply" jacc_dist = distance.jaccard(set1, set2) print(f"Jaccard distance between '{set1}' and '{set2}': {jacc_dist}")
Debug
Known issues
breakingThe `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.
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.
affects: <=0.1.3
gotchaInstalling 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.
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).
affects: <=0.1.3
gotchaThe 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.
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.
affects: <=0.1.3
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'distance'
The 'distance' Python package has not been installed in the current Python environment or the interpreter cannot find it in its search paths.
fix
Install the package using pip: `pip install distance`
error: command 'gcc' failed with exit status 1
The `distance` library includes C extensions, and its installation requires a C compiler (like GCC on Linux/macOS or Microsoft Visual C++ on Windows) and Python development headers, which are missing from the system.
fix
Install a C compiler and Python development files for your operating system. For Debian/Ubuntu, use `sudo apt-get install build-essential python3-dev`. For macOS, use `xcode-select --install`. For Windows, install Microsoft Visual C++ Build Tools.
ImportError: cannot import name 'levenshtein' from 'distance'
The `distance` library exposes functions like `levenshtein` as attributes of the main `distance` module, not as direct imports from the module itself.
fix
Import the `distance` module and then access the function as an attribute: `import distance` followed by `distance.levenshtein(...)`.
Upgrade
Version history
0.1.3latest on PyPI · released Nov 21, 2013
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
16
OpenAI (training)
1
Resources