Registry / data / strsimpy

strsimpy

JSON →
library0.2.1pypypi✓ verified 84d ago

Strsimpy is a Python library that provides implementations for various string similarity and distance measures, including popular algorithms like Levenshtein, Jaro-Winkler, N-Gram, Cosine Similarity, and Jaccard Index. It's designed to be straightforward to use for text analysis and data matching tasks. The current version is 0.2.1. Releases are infrequent, typically addressing bug fixes or adding new algorithms.

pip install strsimpy
INSTALL
IMPORT
SIG · STRSIMPY
S
strsimpy
datapythonv0.2.1
Install
1.6s avg
Import
9ms
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.2.1 · 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.920 runs
installs and imports cleanly · install 0.0s · import 0.010s · 18.1MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.6s · import 0.007s · 19MB
16MB installed
● package 16MB
Code
Verified usage

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

Levenshtein
from strsimpy.levenshtein import Levenshtein
JaroWinkler
from strsimpy.jaro_winkler import JaroWinkler
Ngram
from strsimpy.ngram import Ngram
WeightedLevenshtein
from strsimpy.weighted_levenshtein import WeightedLevenshtein
from strsimpy.weighted_levenshtein import Levenshtein

This quickstart demonstrates calculating Levenshtein distance and Jaro-Winkler similarity between strings. Most algorithms follow a pattern of instantiating a class and then calling a `distance()` or `similarity()` method.

from strsimpy.levenshtein import Levenshtein s0 = "안녕하세요" s1 = "안녕하세유" levenshtein = Levenshtein() distance = levenshtein.distance(s0, s1) print(f"Levenshtein distance between '{s0}' and '{s1}': {distance}") s2 = "apple" s3 = "aple" distance2 = levenshtein.distance(s2, s3) print(f"Levenshtein distance between '{s2}' and '{s3}': {distance2}") from strsimpy.jaro_winkler import JaroWinkler jaro_winkler = JaroWinkler() similarity = jaro_winkler.similarity(s2, s3) print(f"Jaro-Winkler similarity between '{s2}' and '{s3}': {similarity}")
Debug
Known issues
breakingThe package name was changed from `similarity` to `strsimpy`. Old import paths will fail.
fix
Update all `import similarity...` statements to `import strsimpy...` and reinstall the package.
affects: <0.1.2
breakingThe `WeightedLevenshtein` algorithm's API changed significantly in v0.1.7. It now uses functions for weight calculation instead of expecting Class or Objects, simplifying its usage.
fix
Review the documentation for `WeightedLevenshtein` and update your weight calculation logic to use direct functions as arguments, rather than class instances.
affects: <0.1.7
gotchaThe `numpy` dependency was removed in v0.1.5 to lighten the package. If you were implicitly relying on `numpy` being installed alongside `strsimpy`, it might no longer be present.
fix
If your project requires `numpy`, ensure it is explicitly listed in your project's dependencies.
affects: <0.1.5
gotchaA `ZeroDivisionError` was fixed in ShingleBased algorithms (e.g., Jaccard, Cosine Similarity) for certain edge cases.
fix
Upgrade to version 0.1.2 or later to ensure correct calculations and avoid potential runtime errors with ShingleBased algorithms.
affects: <0.1.2
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'strsimpy.JaroWinkler'
String similarity algorithms like JaroWinkler are not directly exposed at the top level of the `strsimpy` module; they reside in their specific submodules within `strsimpy.similarity`.
fix
from strsimpy.similarity.jarowinkler import JaroWinkler
AttributeError: module 'strsimpy' has no attribute 'JaroWinkler'
The `JaroWinkler` class is not a direct attribute of the top-level `strsimpy` module. It must be imported from its specific submodule.
fix
from strsimpy.similarity.jarowinkler import JaroWinkler
jarowinkler_sim = JaroWinkler()
TypeError: object of type 'NoneType' has no len()
One or both of the input arguments passed to a similarity method (e.g., `similarity(s1, s2)`) are not strings, leading to string operations failing.
fix
s1 = str(s1) if s1 is not None else ''
s2 = str(s2) if s2 is not None else ''
similarity_score = your_similarity_object.similarity(s1, s2)
TypeError: __init__() missing 1 required positional argument: 'n'
When initializing an `NGram` similarity object, the required `n` parameter, which defines the size of the n-grams, was not provided.
fix
from strsimpy.similarity.ngram import NGram
ngram_sim = NGram(n=2) # Specify 'n' for bigrams, trigrams, etc.
Upgrade
Version history
0.2.1latest on PyPI · released Sep 10, 2021
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
strsimpy — pip install strsimpy · libregistry