Use this file to discover Exa products, pricing, evaluations, comparisons, use cases, agent interfaces, and technical documentation before exploring further.
Python fuzzy search libraries find strings that nearly match a query despite typos, reordered words, or different spellings. A scorer computes an edit distance or similarity ratio between two strings and ranks candidates by that score. These libraries let apps and AI agents match names and records that differ by a few characters.
Popularity
RapidFuzz has the most monthly downloads among the dedicated fuzzy matching libraries in this comparison, at 143.8M.
def get_closest_match(
string: str,
options: c.Iterable[str],
case_sensitive: bool,
insertion_weight: int = 1,
deletion_weight: int = 1,
substitution_weight: int = 1,
) -> tuple[str, int]:
"""Find the closest match to a given string.
Args:
string:
The string to match.
options:
The options to match against.
case_sensitive:
Whether to match case sensitively.
insertion_weight (optional):
The weight of insertions in the Levenshtein distance. Defaults to 1.
deletion_weight (optional):
The weight of deletions in the Levenshtein distance. Defaults to 1.
substitution_weight (optional):
The weight of substitutions in the Levenshtein distance. Defaults to 1.
Returns:
A pair (closest_match, distance) where closest_match is the closest match to the
given string and distance is the Levenshtein distance between the two.
"""
distances = {
option: distance(
s1=string.lower() if not case_sensitive else string,
s2=option.lower() if not case_sensitive else option,
weights=(insertion_weight, deletion_weight, substitution_weight),
)
for option in options
}
closest_match = min(distances, key=lambda k: distances[k])
return closest_match, distances[closest_match]
jellyfish
Provides approximate string comparison and phonetic encoding functions.
Downloads / mo
11.1M
Stars
2.2K
Last release
1.3.0
License
MIT
Strengths
Compares spelling and pronunciation.Choose string-comparison functions or phonetic encoders for the matching task.
Compares sets of words.Jaccard similarity can compare words or configured character sequences.
Limitations
NYSIIS targets English names.Choose another approach when the relevant pronunciation follows another language.
def spell_check():
spell = SpellChecker()
spell.word_frequency.load_words(known)
num = 0
for line in sys.stdin.readlines():
num += 1
words = list(
filter(
lambda w: w.lower() not in known and w[0] not in "'0123456789"
and len(w) > 4 and all(ord(c) < 128 for c in w),
re.findall(r"[\w']+", line)))
known.update(map(lambda w: w.lower(), words))
print('#', num, end='\r')
time.sleep(0.002)
for identifier in words:
misspelled = spell.unknown(
re.split(r"(?<=[a-z0-9])(?=[A-Z])|_|(?<=[A-Z])(?=[A-Z][a-z])",
identifier))
# Get the one `most likely` answer for word in misspelled:
print('#', num, identifier, '\t',
"s/%s/%s" % (word, spell.correction(word)))
editdistance
Computes Levenshtein distance on strings or sequences of hashable items in C++.
def calculate_cer(self, seqs_hat, seqs_true):
"""Calculate sentence-level CER score.
:param list seqs_hat: prediction
:param list seqs_true: reference
:return: average sentence-level CER score
:rtype float
"""
char_eds, char_ref_lens = [], []
for i, seq_hat_text in enumerate(seqs_hat):
seq_true_text = seqs_true[i]
hyp_chars = seq_hat_text.replace(" ", "")
ref_chars = seq_true_text.replace(" ", "")
char_eds.append(editdistance.eval(hyp_chars, ref_chars))
char_ref_lens.append(len(ref_chars))
return float(sum(char_eds)) / sum(char_ref_lens)
FAQ
RapidFuzz suits most fuzzy matching, with string scorers and ranked extraction from a list of candidates. jellyfish suits phonetic matching such as Soundex and Metaphone. regex suits approximate matching inside a regular expression.
RapidFuzz provides string similarity metrics and ranks a list of candidates against a query. A separate alignment API returns where the match falls in each string.
TheFuzz carries FuzzyWuzzy-style string, token, and partial scores under a new package name. It is implemented on RapidFuzz.
Levenshtein computes edit distance, normalized ratios, and edit operations between two strings. editdistance and Polyleven compute the distance alone, and Polyleven accepts a maximum distance.
For coding agents
Found your fuzzy search library? Help your agent use it.
Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.