{"id":9761,"library":"fuzzy","title":"Fuzzy","description":"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.","status":"active","version":"1.2.2","language":"en","source_language":"en","source_url":"https://github.com/yougov/Fuzzy","tags":["phonetic","soundex","nysiis","metaphone","double metaphone","algorithm","string matching"],"install":[{"cmd":"pip install fuzzy","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"While direct import may work in some environments, the official and most robust way to access algorithms is via the fuzzy module object.","wrong":"from fuzzy import soundex","symbol":"soundex","correct":"import fuzzy\nfuzzy.soundex('example')"},{"note":"Access phonetic algorithms directly from the fuzzy module.","symbol":"nysiis","correct":"import fuzzy\nfuzzy.nysiis('example')"},{"note":"Access phonetic algorithms directly from the fuzzy module.","symbol":"metaphone","correct":"import fuzzy\nfuzzy.metaphone('example')"},{"note":"Access phonetic algorithms directly from the fuzzy module. Note that dm_metaphone returns a tuple.","symbol":"dm_metaphone","correct":"import fuzzy\nfuzzy.dm_metaphone('example')"}],"quickstart":{"code":"import fuzzy\n\nword = 'Washington'\nsoundex_code = fuzzy.soundex(word)\nnysiis_code = fuzzy.nysiis(word)\nmetaphone_code = fuzzy.metaphone(word)\ndm_metaphone_code = fuzzy.dm_metaphone(word)\n\nprint(f\"Original: {word}\")\nprint(f\"Soundex: {soundex_code}\")\nprint(f\"NYSIIS: {nysiis_code}\")\nprint(f\"Metaphone: {metaphone_code}\")\nprint(f\"Double Metaphone: {dm_metaphone_code}\")","lang":"python","description":"This example demonstrates how to import the fuzzy library and apply its main phonetic algorithms (Soundex, NYSIIS, Metaphone, Double Metaphone) to a given word, printing the resulting codes."},"warnings":[{"fix":"Always unpack or index the result of `dm_metaphone`, e.g., `code1, code2 = fuzzy.dm_metaphone('example')`.","message":"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.","severity":"gotcha","affected_versions":">=1.1.0"},{"fix":"Ensure inputs are cast to strings, e.g., `fuzzy.soundex(str(my_number))` or handle potential `None` values before calling the functions.","message":"All phonetic algorithm functions strictly expect string inputs. Passing `None`, integers, or other non-string types will result in a `TypeError`.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Convert the input to a string before passing it to the fuzzy function, e.g., `fuzzy.soundex(str(value))`.","cause":"Attempting to pass a non-string value (like None, int, or float) to a phonetic algorithm function.","error":"TypeError: expected string or bytes-like object"},{"fix":"Verify the function name against the library's documentation. The main functions are `soundex`, `nysiis`, `metaphone`, and `dm_metaphone`.","cause":"Attempting to call a phonetic algorithm function that does not exist or is misspelled within the `fuzzy` module.","error":"AttributeError: module 'fuzzy' has no attribute 'unknown_function'"},{"fix":"pip install fuzzy","cause":"The 'fuzzy' library has not been installed in your Python environment.","error":"ModuleNotFoundError: No module named 'fuzzy'"},{"fix":"from fuzzy import Soundex\ns = Soundex()\nprint(s('hello'))","cause":"You are attempting to import the `Soundex` class using incorrect (lowercase) capitalization. The class names for the phonetic algorithms are capitalized.","error":"ImportError: cannot import name 'soundex' from 'fuzzy'"},{"fix":"import fuzzy\ns = fuzzy.Soundex() # Instantiate the Soundex class\nprint(s('hello'))   # Call the instance to encode a string","cause":"You are trying to call `soundex` as a module-level function, but `Soundex` is a class that needs to be instantiated before it can be used as a callable object.","error":"AttributeError: module 'fuzzy' has no attribute 'soundex'"}]}