Pyphonetics

raw JSON →
0.5.3 verified Fri May 01 auth: no python

A Python 3 library for phonetic encoding algorithms including Soundex, Metaphone, Double Metaphone, and others. Current version is 0.5.3, with infrequent releases.

pip install pyphonetics
error AttributeError: module 'pyphonetics' has no attribute 'Soundex'
cause Incorrect import: `import pyphonetics` then `pyphonetics.Soundex()`.
fix
Use from pyphonetics import Soundex directly.
error TypeError: 'str' object is not callable
cause Overwriting the `phonetics` function variable name, e.g., `phonetics = 'foo'`.
fix
Avoid using phonetics as a variable name.
error ValueError: The word must contain only letters
cause Input contains numbers or special characters.
fix
Strip non-alphabetic characters: re.sub(r'[^A-Za-z]', '', word).
deprecated The `phonetics` function returns a tuple in older versions but now returns a string; check return type.
fix Update code to expect a string or use `from pyphonetics import Soundex; code = soundex.phonetics('word')` and treat as string.
gotcha Case sensitivity: the library expects uppercase input for some algorithms; inconsistent behavior may occur.
fix Always convert input to uppercase before passing: `soundex.phonetics(word.upper())`
breaking In version 0.5.0, the `phonetics` method was changed from returning a list/generator to returning a string for single results; DoubleMetaphone changed to return a tuple.
fix Check the return type: for DoubleMetaphone, use `result = dm.phonetics(word); primary, secondary = result`.
gotcha The library does not support non-alphabetic characters well; numbers or punctuation may cause errors or silent failures.
fix Sanitize input to only contain letters (A-Z) before encoding.

Encode a word using Soundex phonetic algorithm.

from pyphonetics import Soundex
soundex = Soundex()
print(soundex.phonetics('example'))