matchr
Fast fuzzy string matching — written in Rust, usable from Python.
Install
Python quick start
# find the closest match
# → ('Oatly Oat Drink 1L', 0.902)
# filter weak matches with a threshold
# → None
# match many queries at once
# → [('Oatly Oat Drink 1L', 0.902), ('Felix Cat Food 400g', 0.843)]
Rust usage
use ;
Algorithms
- Levenshtein — minimum edit distance between two strings. Lower = more similar.
- Jaro-Winkler — similarity score from
0.0to1.0, optimised for names and short strings. Gives a bonus for shared prefixes. - Trigram — splits strings into overlapping 3-character chunks, scores overlap using the Dice coefficient. Good for longer strings and typo detection.
- Token sort / token set — order-invariant scorers built on top of
combined_score. Sorts (and optionally deduplicates) whitespace-separated tokens before comparing, so"Oat Drink Oatly 1L"and"Oatly Oat Drink 1L"come out equal. - Combined score — weighted blend of Levenshtein, Jaro-Winkler, and trigram. Used internally by
best_match,rank_matches, andbatch_best_match.
Benchmarks
See benchmarks/ for the criterion suite (cargo bench) and a Python comparison vs rapidfuzz. There's also a demo notebook that walks through deduping a synthetic 10k-product catalog end-to-end.
Notes
- All functions normalise input (trim + lowercase + strip diacritics) before comparing —
"Café"and"cafe"are treated as equal levenshteinreturnsusize(edit distance), all others returnf64(0.0–1.0)- Python functions accept an optional
thresholdparameter — results below it are filtered out batch_best_matchis parallelised via rayon and pre-normalises the candidate list once, so it scales with available cores