Indic Num To Words
Indic-numtowords is a Python module developed by AI4Bharat that converts numbers into their word representations for various Indian languages and English (India). It supports languages such as Hindi, Nepali, Gujarati, Marathi, Bengali, Telugu, Tamil, Kannada, Oriya, Punjabi, and Malayalam. The library is currently at version 1.1.0, with an irregular release cadence.
Warnings
- gotcha There are two distinct Python libraries with very similar names: `indic-numtowords` (from AI4Bharat) and `indic-num2words` (from raj-sutariya). They have different import paths and function names (`num2words` vs `num_to_word`). Ensure you install and import the correct library based on your intended use.
- gotcha The `lang` parameter requires specific ISO language codes (e.g., 'hi' for Hindi, 'en' for English-India, 'ta' for Tamil). Providing an unsupported or incorrect language code will result in an error or unexpected output.
- gotcha The primary `num2words` function is designed for converting non-negative integers. While it accepts `int` or `str` input, explicit support for converting decimals (e.g., 'forty-two point one') or currency formats is not directly documented as a core feature of the main conversion function, though there is discussion about adding it.
Install
-
pip install indic-numtowords
Imports
- num2words
from num_to_words import num_to_word
from indic_numtowords import num2words
Quickstart
from indic_numtowords import num2words
# Convert a number to words in Hindi
hindi_words = num2words(36, lang='hi')
print(f"36 in Hindi: {hindi_words}")
# Convert a number to words in English (India)
english_words = num2words(150, lang='en')
print(f"150 in English: {english_words}")
# Convert with variations (if available for language and number)
# Note: The 'variations' parameter might not yield different results for all numbers/languages.
hindi_variations = num2words(150, lang='hi', variations=True)
print(f"150 in Hindi with variations: {hindi_variations}")
# Convert each digit separately
split_digits = num2words(123, lang='en', split=True)
print(f"123 (split) in English: {split_digits}")