python-string-similarity is a collection of string similarity and distance measures for Python. The algorithms are implemented in Rust and exposed through PyO3, so comparisons are fast while the public Python API remains compatible with the original pure-Python releases.
Install
pip install -U strsimpySupported on Python 3.10-3.13. Prebuilt abi3 wheels cover Linux, macOS and Windows; see Installation for platforms and source-build requirements.
A first comparison
from strsimpy import JaroWinkler, Levenshtein
Levenshtein().distance("kitten", "sitting") # 3
JaroWinkler().similarity("MARTHA", "MARHTA") # 0.9611111111111111Every public class can be imported from the package root. The historical per-module imports, such as from strsimpy.levenshtein import Levenshtein, keep working too.
Feature families
| Family | Measures | What it gives you |
|---|---|---|
| Edit distance | Levenshtein, WeightedLevenshtein, Damerau, OptimalStringAlignment, LongestCommonSubsequence, MetricLCS |
Character-level edit costs and their normalized variants |
| Normalized similarity | NormalizedLevenshtein, JaroWinkler, MLIPNS, RatcliffObershelp, plus the Strcmp95 routine |
Scores in the range 0.0 to 1.0 for ranking candidates |
| Shingle and token metrics | NGram, QGram, Cosine, Jaccard, SorensenDice, OverlapCoefficient, Tversky, Tanimoto, Bag, MongeElkan |
Set, profile and token comparisons for words and documents |
| Sequence alignment | NeedlemanWunsch, SmithWaterman, Gotoh |
Raw alignment scores and optional alignment paths |
| Compression | NormalizedCompressionDistance |
Compression-based distance with a run-length encoder |
| Experimental | SIFT4 |
Human-oriented edit distance with optional tokenizers |
Why the Rust core?
- Fast by default. The hot loops run in compiled Rust, including rolling-row edit distances and shingle profiles.
- Easy to deploy. A single abi3 extension module ships in prebuilt wheels for CPython 3.10 and newer.
- Familiar API. Class names, constructor options, module paths and method names from the pure-Python package are preserved.
- Unicode aware. Algorithms operate on Unicode scalar values, matching Python’s
len(str)and indexing semantics.
Explore the docs
Quickstart
Run representative distance, similarity, alignment and compression measures in a few lines of Python.
Algorithms
Understand how each measure works, what its values mean, and when to choose it.
API reference
Look up classes, constructors, methods, return types and caveats.
Source code, issues and release notes live on GitHub. The project is MIT licensed.