{"id":6608,"library":"doublemetaphone","title":"Double Metaphone for Python","description":"The `doublemetaphone` library provides a Python wrapper for the C++ implementation of the Double Metaphone phonetic algorithm. This algorithm generates approximate phonetic representations (codes) for words, useful for matching names or words with similar pronunciations despite different spellings. The current version is 1.2. Releases appear to be infrequent, with significant gaps between updates.","status":"active","version":"1.2","language":"en","source_language":"en","source_url":"https://github.com/dedupeio/doublemetaphone","tags":["phonetics","string-matching","nlp","fuzzy-matching","metaphone"],"install":[{"cmd":"pip install doublemetaphone","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"This is a Python wrapper for a C++ library. While pre-built wheels are often available, a C++ compiler (like GCC or MSVC) is required if installing from source or for platforms without pre-built wheels.","package":"C++ compiler","optional":true}],"imports":[{"note":"The primary function is directly exposed from the top-level package, not nested further.","wrong":"import doublemetaphone; doublemetaphone.doublemetaphone.doublemetaphone('word')","symbol":"doublemetaphone","correct":"from doublemetaphone import doublemetaphone"}],"quickstart":{"code":"from doublemetaphone import doublemetaphone\n\nword1 = \"Smith\"\nword2 = \"Schmidt\"\n\nprimary1, secondary1 = doublemetaphone(word1)\nprimary2, secondary2 = doublemetaphone(word2)\n\nprint(f\"'{word1}': Primary='{primary1}', Secondary='{secondary1}'\")\nprint(f\"'{word2}': Primary='{primary2}', Secondary='{secondary2}'\")\n\n# Double Metaphone often returns two codes to account for phonetic ambiguities.\n# For example, 'Smith' and 'Schmidt' share a secondary code.\nif primary1 == primary2 or secondary1 == secondary2 or primary1 == secondary2 or primary2 == secondary1:\n    print(f\"'{word1}' and '{word2}' are phonetically similar.\")","lang":"python","description":"Generate Double Metaphone codes for a word and compare them. The function returns a tuple of (primary_code, secondary_code)."},"warnings":[{"fix":"Always unpack the return value into two variables: `primary, secondary = doublemetaphone('word')`.","message":"The `doublemetaphone` function returns a tuple of two strings (primary and secondary codes), not a single string. Ensure your code handles both return values, even if one is an empty string.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure all input strings are Python 3 `str` objects (Unicode). Explicitly decode byte strings if necessary (e.g., `my_bytes.decode('utf-8')`).","message":"Older versions (primarily Python 2) might have raised `TypeError` if non-unicode strings were passed. Python 3 strings are Unicode by default, but be mindful of encoding if dealing with byte strings or legacy data.","severity":"breaking","affected_versions":"<1.1 (Python 2), potential edge cases in 1.x with bytes"},{"fix":"Verify the `pip install` command and `import` statement match the `doublemetaphone` package specifically. Check the PyPI project description to confirm it's the C++ wrapper.","message":"There are multiple Python packages implementing or wrapping Metaphone/Double Metaphone algorithms (e.g., `metaphone`, `phonetics`, `doublemetaphone`). Ensure you install and import the correct package for the C++ wrapper implementation (`doublemetaphone`).","severity":"gotcha","affected_versions":"All versions"},{"fix":"If `pip install` fails with compilation errors, install a C++ compiler (e.g., build-essential on Linux, Xcode Command Line Tools on macOS, Visual C++ Build Tools on Windows) or consider using a pre-packaged environment (e.g., Docker).","message":"Installation might require a C++ compiler if a pre-built wheel is not available for your specific Python version and operating system. This is common for Python wrappers around C/C++ libraries.","severity":"gotcha","affected_versions":"All versions, on environments without compatible wheels"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}