matchr-rs 0.1.1

Fast fuzzy string matching — Levenshtein, Jaro-Winkler, and trigram similarity. Usable from Rust and Python.
Documentation
  • Coverage
  • 46.15%
    6 out of 13 items documented6 out of 7 items with examples
  • Size
  • Source code size: 22.67 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 405 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • mommo-codes/matchr
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • mommo-codes

matchr

PyPI

Fast fuzzy string matching — written in Rust, usable from Python.

Install

pip install matchr

Python quick start

from matchr import best_match, rank_matches, batch_best_match

# find the closest match
best_match("oatly oat drink", ["Oatly Oat Drink 1L", "Oat Milk", "Oatly Barista"])
# → ('Oatly Oat Drink 1L', 0.902)

# filter weak matches with a threshold
best_match("xyz gibberish", ["Oatly Oat Drink 1L"], threshold=0.7)
# → None

# match many queries at once
batch_best_match(["oatly oat drink", "felix cat food"], catalog, threshold=0.7)
# → [('Oatly Oat Drink 1L', 0.902), ('Felix Cat Food 400g', 0.843)]

Rust usage

use matchr::{levenshtein, jaro_winkler, trigram_similarity};

fn main() {
    println!("{}", levenshtein("cat", "bat"));           // 1
    println!("{}", jaro_winkler("martha", "marhta"));    // 0.961
    println!("{}", trigram_similarity("hello", "helo")); // 0.4
}

Algorithms

  • Levenshtein — minimum edit distance between two strings. Lower = more similar.
  • Jaro-Winkler — similarity score from 0.0 to 1.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.
  • Combined score — weighted blend of all three, used internally by best_match and rank_matches.

Notes

  • All functions normalise input (lowercase + trim) before comparing
  • levenshtein returns usize (edit distance), all others return f64 (0.0–1.0)
  • Python functions accept an optional threshold parameter — results below it are filtered out