Phonetics

1.0.5 · maintenance · verified Thu Apr 16

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

import phonetics

# Soundex algorithm
print(f"Soundex for 'Python': {phonetics.soundex('Python')}")
print(f"Soundex for 'Pythn': {phonetics.soundex('Pythn')}")

# Metaphone algorithm
print(f"Metaphone for 'example': {phonetics.metaphone('example')}")
print(f"Metaphone for 'xylophone': {phonetics.metaphone('xylophone')}")

# Double Metaphone algorithm
# Returns a tuple of primary and secondary keys
primary_key, secondary_key = phonetics.dmetaphone('Danger')
print(f"Double Metaphone for 'Danger': ({primary_key}, {secondary_key})")

primary_key, secondary_key = phonetics.dmetaphone('Denger')
print(f"Double Metaphone for 'Denger': ({primary_key}, {secondary_key})")

view raw JSON →