Skip to main content

wiktionary-ipa

PyPI version Python versions License: MIT Tests

A fast, lightweight, standalone Python library to extract, normalize, and verify British English (Received Pronunciation / RP) International Phonetic Alphabet (IPA) transcriptions directly from en.wiktionary.org.

Zero external dependencies — Python standard library only.


Why wiktionary-ipa?

  • Dedicated to British English (RP / SSB): Most English phonetic libraries (eng-to-ipa, CMUdict) default strictly to General American and introduce rhotic errors or flaps. wiktionary-ipa enforces strict RP priority and disqualifies Americanisms (GA, US, flaps [ɾ], rhotic vowels [ɚ, ɝ]).
  • Live Action API Batching: Queries en.wiktionary.org using batched requests (up to 50 words per HTTP request) with gzip compression and polite rate limiting.
  • Zero Cache, Zero Bloat: Always queries the live crowd-sourced truth from Wiktionary without requiring multi-gigabyte XML dump downloads or stale databases.
  • Homograph Disambiguation: Correctly resolves noun vs. verb stress pairs (e.g., record N -> /ˈrekɔːd/ vs. record V -> /rɪˈkɔːd/).
  • Compound Prosody Synthesis: Automatically constructs natural British English stress patterns for idioms, phrasal verbs, and compounds missing dedicated dictionary entries.
  • Phonetic Equivalence Engine: Intelligently matches variant representations (syllabic consonants like ʃn vs. ʃən, linking (r), optional yods (j), and optional plurals).

Installation

pip install wiktionary-ipa

Or install directly from GitHub:

pip install git+https://github.com/thanhqng1510/wiktionary-ipa.git

Quick Python API

import wiktionary_ipa as wipa

# 1. Single Word Lookup (Live Web)
ipa = wipa.lookup("abbreviation")
print(ipa)  # /əˌbriːviˈeɪʃən/

# 2. Batch Lookup (50 titles per HTTP request, gzip-compressed)
results = wipa.batch_lookup(["apple", "banana", "record N", "record V"])
# {
#   "apple": "/ˈæp.əl/",
#   "banana": "/bəˈnɑː.nə/",
#   "record N": "/ˈrekɔːd/",
#   "record V": "/rɪˈkɔːd/"
# }

# 3. Verify Word Against Live Web
res = wipa.verify_word("backward(s)", "/ˈbækwəd(z)/")
print(res["status"])  # 'EQUIVALENT' (matches live /bækwə(r)d/)

# 4. Phonetic Equivalence Check
wipa.phonetically_equivalent("/ˈbækwəd(z)/", "/ˈbækwə(r)d/")  # True
wipa.phonetically_equivalent("/əˈdɪʃn/", "/əˈdɪʃən/")         # True

# 5. Normalizer
wipa.normalize_ipa("[ˈbeɾə]")  # '/ˈbetə/'

Command-Line Interface (CLI)

wiktionary-ipa provides a fast CLI:

# Lookup single word
wiktionary-ipa "abbreviation"
# abbreviation: /əˌbriːviˈeɪʃən/

# Batch lookup
wiktionary-ipa apple banana cucumber

# Verify expected pronunciation against live Wiktionary
wiktionary-ipa --verify "sea bass" "/ˈsiː bæs/"
# Word: sea bass
# Status: MATCH
# Expected: /ˈsiː bæs/
# Live Web: /ˈsiː bæs/

# JSON output for CI automation
wiktionary-ipa --verify "backward(s)" "/ˈbækwəd(z)/" --json

Architecture & Modules

  • client.py (WiktionaryClient): Handles MediaWiki Action API communication, batching up to 50 titles, HTTP gzip decompression, polite throttling (0.35s), and exponential backoff on HTTP 429/503.
  • dialects.py: Received Pronunciation scoring (+100 for RP/SSB, +90 for UK/British) and hard rejection filters for non-RP accents (US, GA, Canada, Australia, Scotland, Ireland).
  • normalizer.py: Cleans IPA formatting, enforces Unicode slashes, standardizes script characters (e.g. ɡ -> g), and evaluates phonetic equivalence.
  • parser.py: Extracts English pronunciation sections from raw Wikitext, parses {{IPA|en|...}} templates, filters dialect tags, and resolves POS homographs.
  • prosody.py: Synthesizes compound noun stress, phrasal verb nuclear stress, and grammatical weak forms when an exact multi-word Wiktionary entry is absent.

Running Tests

All 22 unit tests execute in ~0.001 seconds using the standard library unittest runner:

python3 -m unittest discover -s tests

License

MIT License. See LICENSE for details.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wiktionary_ipa-0.1.0.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wiktionary_ipa-0.1.0-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file wiktionary_ipa-0.1.0.tar.gz.

File metadata

  • Download URL: wiktionary_ipa-0.1.0.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for wiktionary_ipa-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ec4e257efc807ca9b13cbeba8e777073e45b104e5578bf11bef19168ee2d341e
MD5 a5b41ea2a1f72f84ed9b7e3b26d933fb
BLAKE2b-256 bf5685c86519a6cb940ebd617348074215cb1013acd370bd51ec32c83acf70fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for wiktionary_ipa-0.1.0.tar.gz:

Publisher: publish.yml on thanhqng1510/wiktionary-ipa

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file wiktionary_ipa-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: wiktionary_ipa-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for wiktionary_ipa-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6b5e487917020eda70f297b28afdd00a59cfffceeecb715b69fd68a803e97393
MD5 1aba36b62c19f4d5ee0979a04cf94f62
BLAKE2b-256 7cfe23cc556359c8995adbfa65051edfd241b00a8e02e7ae628fa7887ff141d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for wiktionary_ipa-0.1.0-py3-none-any.whl:

Publisher: publish.yml on thanhqng1510/wiktionary-ipa

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page