{"id":8414,"library":"phonetics","title":"Phonetics","description":"The `phonetics` library is a Python module designed to compute phonetic keys of strings for indexing or fuzzy matching. It implements several classic phonetic algorithms including Soundex, NYSISS, Metaphone, and Double Metaphone. The library's last release was in March 2018, and it is marked with a '3 - Alpha' development status, primarily supporting Python 2.x and early Python 3.x versions up to 3.5.","status":"maintenance","version":"1.0.5","language":"en","source_language":"en","source_url":"https://github.com/Zack--/phonetics","tags":["phonetics","soundex","metaphone","double metaphone","fuzzy matching","natural language processing","nlp","string comparison"],"install":[{"cmd":"pip install phonetics","lang":"bash","label":"Install stable release"}],"dependencies":[],"imports":[{"note":"The library typically exposes functions directly under the 'phonetics' module rather than as separate classes or methods for each algorithm. You call functions like `phonetics.soundex()` or `phonetics.metaphone()` directly.","wrong":"from phonetics import Soundex","symbol":"phonetics","correct":"import phonetics"}],"quickstart":{"code":"import phonetics\n\n# Soundex algorithm\nprint(f\"Soundex for 'Python': {phonetics.soundex('Python')}\")\nprint(f\"Soundex for 'Pythn': {phonetics.soundex('Pythn')}\")\n\n# Metaphone algorithm\nprint(f\"Metaphone for 'example': {phonetics.metaphone('example')}\")\nprint(f\"Metaphone for 'xylophone': {phonetics.metaphone('xylophone')}\")\n\n# Double Metaphone algorithm\n# Returns a tuple of primary and secondary keys\nprimary_key, secondary_key = phonetics.dmetaphone('Danger')\nprint(f\"Double Metaphone for 'Danger': ({primary_key}, {secondary_key})\")\n\nprimary_key, secondary_key = phonetics.dmetaphone('Denger')\nprint(f\"Double Metaphone for 'Denger': ({primary_key}, {secondary_key})\")","lang":"python","description":"Demonstrates how to import the `phonetics` module and use its core phonetic encoding functions like `soundex`, `metaphone`, and `dmetaphone` to generate phonetic keys for strings."},"warnings":[{"fix":"Consider using alternative, actively maintained phonetic libraries like `pyphonetics`, `cologne-phonetics`, or `fuzzywuzzy` for modern Python environments. If you must use `phonetics`, run it in a Python 3.5 or earlier environment.","message":"The `phonetics` library explicitly supports Python versions up to 3.5. Running it on newer Python versions (3.6+) may lead to compatibility issues, unexpected errors, or incorrect behavior due to changes in Python's standard library or language syntax over time.","severity":"breaking","affected_versions":"Python 3.6+"},{"fix":"Evaluate alternatives for new projects. If using it, thoroughly test its behavior in your specific environment and use case. Be aware that community support or bug fixes are unlikely.","message":"The library is in 'Alpha' development status, indicating it may not be production-ready and could have undocumented quirks or bugs. Its last release was in 2018, suggesting a lack of active maintenance and potential security vulnerabilities.","severity":"gotcha","affected_versions":"All versions (1.x.x)"},{"fix":"For advanced phonetic analysis, IPA support, or multi-language phonetics, consider libraries like `epitran`, `panphon`, `gruut-ipa`, or `phonecodes`. This library is best suited for simple, traditional phonetic encoding tasks.","message":"The `phonetics` library focuses on traditional phonetic algorithms (Soundex, Metaphone, NYSISS) for string key generation, which are primarily designed for English or Germanic languages. It does not provide advanced linguistic analysis, IPA (International Phonetic Alphabet) transcription, or support for a wide range of global languages.","severity":"gotcha","affected_versions":"All versions (1.x.x)"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure that the input strings to phonetic functions are valid (non-empty, appropriate characters). Wrap calls in a `try-except` block to gracefully handle `None` returns or `TypeError`s. Example: `result = phonetics.dmetaphone(my_string); if result: print(result)`.","cause":"This error often occurs when one of the phonetic functions (e.g., `dmetaphone`) is called with an input that results in `None` being returned for one of its internal steps, and subsequent operations try to apply a length check to this `None` value. This can happen with unusual or empty string inputs, especially with older Python versions.","error":"TypeError: object of type 'NoneType' has no len()"},{"fix":"Verify the exact functions and classes exposed by *this* `phonetics` library by consulting its PyPI page or source code (Soundex, NYSISS, Metaphone, Double Metaphone are confirmed). If you need other algorithms, install and use a different library.","cause":"Users might expect functionalities or algorithms present in other `phonetics`-related libraries (e.g., `pyphonetics`, `cologne-phonetics`) or newer versions of general phonetic tools to be available in this specific `phonetics` library.","error":"AttributeError: module 'phonetics' has no attribute 'some_new_function'"}]}