Registry / data / metaphone

metaphone

JSON →
library0.6pypypi✓ verified 85d ago

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.

pip install metaphone
INSTALL
IMPORT
SIG · METAPHONE
M
metaphone
datapythonv0.6
Install
2.4s avg
Import
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.6 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.3MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.4s · import 0.000s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

doublemetaphone
from metaphone import doublemetaphone
metaphone
from metaphone import metaphone

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.

from metaphone import doublemetaphone word = "architect" primary_code, secondary_code = doublemetaphone(word) print(f"Original word: {word}") print(f"Double Metaphone codes: Primary='{primary_code}', Secondary='{secondary_code}'") word_two = "Schmidt" primary_code_two, secondary_code_two = doublemetaphone(word_two) print(f"Original word: {word_two}") print(f"Double Metaphone codes: Primary='{primary_code_two}', Secondary='{secondary_code_two}'") from metaphone import metaphone word_three = "example" metaphone_code = metaphone(word_three) print(f"Original word: {word_three}") print(f"Metaphone code: '{metaphone_code}'")
Debug
Known issues
breakingThe `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.
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.
affects: <=0.6
gotchaThe 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).
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.
affects: *
Errors
Common errors & fixes
SyntaxError: invalid syntax (on `next = self.next_chars.pop(0)`)
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`.
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.
AttributeError: 'SomeClass' object has no attribute 'next'
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.
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.
Upgrade
Version history
0.6latest on PyPI · released Aug 24, 2016
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
metaphone — pip install metaphone · libregistry