{"id":7406,"library":"metaphone","title":"Metaphone","description":"Metaphone is a Python library that provides implementations of the Metaphone and Double Metaphone phonetic algorithms. These algorithms are designed to index words by their English pronunciation, offering an improvement over Soundex for matching similar-sounding words and names, even with variations in spelling. The Double Metaphone algorithm further refines this by accounting for spelling peculiarities from various languages and can return both a primary and a secondary phonetic code. The current version is 0.6, and the project has a very slow release cadence, with the last PyPI update in 2016 and the latest GitHub release in 2020.","status":"maintenance","version":"0.6","language":"en","source_language":"en","source_url":"https://github.com/oubiwann/metaphone","tags":["phonetics","metaphone","doublemetaphone","string matching","fuzzy logic","nlp"],"install":[{"cmd":"pip install metaphone","lang":"bash","label":"PyPI"}],"dependencies":[],"imports":[{"symbol":"doublemetaphone","correct":"from metaphone import doublemetaphone"},{"symbol":"metaphone","correct":"from metaphone import metaphone"}],"quickstart":{"code":"from metaphone import doublemetaphone\n\nword = \"architect\"\nprimary_code, secondary_code = doublemetaphone(word)\nprint(f\"Original word: {word}\")\nprint(f\"Double Metaphone codes: Primary='{primary_code}', Secondary='{secondary_code}'\")\n\nword_two = \"Schmidt\"\nprimary_code_two, secondary_code_two = doublemetaphone(word_two)\nprint(f\"Original word: {word_two}\")\nprint(f\"Double Metaphone codes: Primary='{primary_code_two}', Secondary='{secondary_code_two}'\")\n\nfrom metaphone import metaphone\nword_three = \"example\"\nmetaphone_code = metaphone(word_three)\nprint(f\"Original word: {word_three}\")\nprint(f\"Metaphone code: '{metaphone_code}'\")","lang":"python","description":"This quickstart demonstrates how to import and use both the `doublemetaphone` and `metaphone` functions to generate phonetic codes for words. Double Metaphone returns a tuple of two codes (primary and secondary), while Metaphone returns a single code."},"warnings":[{"fix":"Users are advised to use a Python 3 compatible fork or implement a workaround by renaming the `next` method in the source code if direct use of this specific package is required. Several alternative, actively maintained libraries (e.g., `phonetics`, `abydos`) provide Metaphone and Double Metaphone algorithms with Python 3 support.","message":"The `metaphone` library (version 0.6 and earlier) contains Python 2 specific syntax, particularly the use of `self.next` as a method name, which is a reserved keyword in Python 3. This will cause `SyntaxError` or `AttributeError` when run directly in Python 3 environments.","severity":"breaking","affected_versions":"<=0.6"},{"fix":"For highly accurate phonetic matching across diverse languages, consider specialized phonetic libraries or commercial alternatives like Metaphone 3 if your use case demands it. For this library, be aware of its English-centric design.","message":"The Metaphone algorithm itself (and by extension, this library's implementation) is primarily designed for English pronunciation. While Double Metaphone attempts to account for other language irregularities, its accuracy may vary significantly for non-English words or names, compared to language-specific phonetic algorithms or more advanced systems like Metaphone 3 (which is commercial).","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"This issue requires modifying the library's source code to rename the `next` method (e.g., to `_next_char`). Alternatively, use a Python 3 compatible fork or a different library that supports Metaphone algorithms on Python 3.","cause":"The `metaphone` library was written for Python 2, where `next` was not a reserved keyword. In Python 3, `next` is a built-in function, leading to a `SyntaxError` when a method or variable is named `next`.","error":"SyntaxError: invalid syntax (on `next = self.next_chars.pop(0)`)"},{"fix":"As above, this requires a modification of the library's source code to rename the conflicting `next` method or usage of a Python 3 compatible alternative library. For example, changing `self.next` to `self._next` in the original library's `metaphone.py` file could resolve this.","cause":"Similar to the `SyntaxError`, this typically arises in Python 3 environments when code attempts to call a method named `next` within the `metaphone` library, which conflicts with Python 3's built-in `next()` function and is likely not properly defined due to the `SyntaxError` in the original source.","error":"AttributeError: 'SomeClass' object has no attribute 'next'"}]}