strsimpy groups its algorithms by the kind of comparison they perform. The pages below cover formulas, complexity, empty-input behavior, and known limitations for every public class.
Edit distance
Levenshtein, Weighted Levenshtein, Damerau, Optimal String Alignment, MLIPNS, and Strcmp95.
Sequence similarity
Jaro-Winkler, Longest Common Subsequence, Metric LCS, and Ratcliff-Obershelp.
Shingle-based
N-Gram, Q-Gram, Cosine, Jaccard, Sorensen-Dice, Overlap, Tversky, and Tanimoto.
Token-based
Bag distance and Monge-Elkan for token or character multisets.
Sequence alignment
Needleman-Wunsch, Smith-Waterman, and Gotoh scores with optional alignment paths.
Compression
Normalized compression distance with a run-length encoder.
Experimental
SIFT4, its options, and its tokenizers.
Choosing a measure
Use the selection guide for a task-oriented comparison. In short:
- Use Levenshtein or Damerau when you need an edit count, and choose the normalized variants when you need a 0-1 score.
- Use Jaro-Winkler or Strcmp95 for short names and typo-heavy record linkage.
- Use Jaccard, Cosine, Tversky, or Tanimoto for documents represented as shingles or sets.
- Use Monge-Elkan for token sequences such as names or short addresses.
- Use the alignment classes when you need the alignment path or affine gap scoring, and Ratcliff-Obershelp when you want a Gestalt/difflib-style ratio.
- Use NormalizedCompressionDistance only when a compressor-based distance is appropriate and its limitations are acceptable.
Properties at a glance
| Class | Kind | Normalized | Metric | Notes |
|---|---|---|---|---|
Levenshtein |
distance | No | Yes | Uniform edit costs |
NormalizedLevenshtein |
distance + similarity | Yes | No | Edit count divided by the longer length |
WeightedLevenshtein |
distance | No | No | Callables define insertion, deletion, and substitution costs |
Damerau |
distance | No | Yes | Unrestricted adjacent transpositions |
OptimalStringAlignment |
distance | No | No | Restricted transpositions; exposes alignment() |
JaroWinkler |
similarity + distance | Yes | No | Prefix-boosted Jaro score |
MLIPNS |
similarity + distance | Yes | No | Binary product-name heuristic |
Strcmp95 |
similarity + distance | Yes | No | Census Jaro-Winkler variant |
LongestCommonSubsequence |
distance | No | No | Insertions and deletions only |
MetricLCS |
distance | Yes | Yes | Normalized LCS distance |
RatcliffObershelp |
similarity + distance | Yes | No | Gestalt pattern matching |
NGram |
distance | Yes | No | Kondrak’s normalized n-gram distance |
QGram |
distance | No | No | L1 profile distance |
Cosine |
similarity + distance | Yes | No | Profile cosine |
Jaccard |
similarity + distance | Yes | Yes | Shingle sets |
SorensenDice |
similarity + distance | Yes | No | Shingle sets |
OverlapCoefficient |
similarity + distance | Yes | No | Shingle sets |
Tversky |
similarity + distance | Yes | No | Asymmetric when alpha != beta |
Tanimoto |
similarity + distance | Yes | Yes | Standard set Tanimoto (Jaccard) |
Bag |
distance | No | Yes | Character multiset distance |
MongeElkan |
similarity + distance | Yes | No | Token sequences |
NeedlemanWunsch |
score + alignment | No | No | Global, linear gap |
SmithWaterman |
score + alignment | No | No | Local, linear gap |
Gotoh |
score + alignment | No | No | Global, affine gap |
NormalizedCompressionDistance |
distance | No | No | RLE compressor only |
SIFT4 |
distance | No | No | Experimental |