Skip to content

python-string-similarity

Rust-backed string similarity and distance measures for Python, with a pure Rust core and a stable PyO3 API.

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 strsimpy

Supported 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.9611111111111111

Every 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

Source code, issues and release notes live on GitHub. The project is MIT licensed.

Type to search…

↑↓ navigate↵ selectEsc close