Fuzzy
Fuzzy is a Python library providing fast implementations of phonetic algorithms such as Soundex, NYSIIS, Metaphone, and Double Metaphone. It is currently at version 1.2.2. Its release cadence is generally infrequent, focusing on stability and bug fixes for its core set of algorithms.
Common errors
-
TypeError: expected string or bytes-like object
cause Attempting to pass a non-string value (like None, int, or float) to a phonetic algorithm function.fixConvert the input to a string before passing it to the fuzzy function, e.g., `fuzzy.soundex(str(value))`. -
AttributeError: module 'fuzzy' has no attribute 'unknown_function'
cause Attempting to call a phonetic algorithm function that does not exist or is misspelled within the `fuzzy` module.fixVerify the function name against the library's documentation. The main functions are `soundex`, `nysiis`, `metaphone`, and `dm_metaphone`.
Warnings
- gotcha The `dm_metaphone` (Double Metaphone) function returns a tuple of two phonetic codes (or one code and None), unlike other algorithms which return a single string.
- gotcha All phonetic algorithm functions strictly expect string inputs. Passing `None`, integers, or other non-string types will result in a `TypeError`.
Install
-
pip install fuzzy
Imports
- soundex
from fuzzy import soundex
import fuzzy fuzzy.soundex('example') - nysiis
import fuzzy fuzzy.nysiis('example') - metaphone
import fuzzy fuzzy.metaphone('example') - dm_metaphone
import fuzzy fuzzy.dm_metaphone('example')
Quickstart
import fuzzy
word = 'Washington'
soundex_code = fuzzy.soundex(word)
nysiis_code = fuzzy.nysiis(word)
metaphone_code = fuzzy.metaphone(word)
dm_metaphone_code = fuzzy.dm_metaphone(word)
print(f"Original: {word}")
print(f"Soundex: {soundex_code}")
print(f"NYSIIS: {nysiis_code}")
print(f"Metaphone: {metaphone_code}")
print(f"Double Metaphone: {dm_metaphone_code}")