text2digits
A small library to convert text numbers to digits in a string
What it is and what it does
text2digits is a lightweight Python library that recognizes number words written as text—like "twenty ten", "one thousand six hundred sixty six", or "negative thirty seven"—and replaces them with their numeric equivalents in a string. It handles both cardinal numbers (one, two, three) and ordinals (first, second, third), supports informal year-style concatenation ("twenty ten" becomes "2010"), and works with multiple number systems including the Indian scales (lakh, crore, arab, kharab). The library is designed for post-processing speech-to-text output, particularly from voice assistants like Alexa or Lex, where spoken numbers arrive as words and need to be normalized to digits.
The package has no runtime dependencies and installs as a pure Python wheel. It recognizes a wide variety of phrasings—both formal and conversational—and can correct minor spelling variations. Known limitations include that negative numbers preserve the word "negative" rather than converting to a minus sign, and ordinal suffixes are dropped by default ("third" becomes "3" not "3rd") unless explicitly enabled. Decimal literals adjacent to scale words are supported ("2.5 thousand" becomes "2500").
Use it for:
- Clean up Alexa or Lex transcription output where spoken numbers appear as words rather than digits.
- Normalize user input from voice interfaces before storing or processing numeric data.
- Parse informal written descriptions containing number words (e.g., chat logs, survey responses) into machine-readable form.
- Convert year expressions in narrative text ("born in nineteen ninety two") to standard numeric format.
- Handle ordinal references in text ("the fourth cousin") by converting them to digit form for indexing or comparison.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Converts written-out number words in text to their digit equivalents, handling both formal and informal phrasing across a range of scales and styles.
Yes. The package is lightweight, actively maintained, has no dependencies, and solves a specific problem well—converting spoken/written number words to digits. It's particularly valuable if you work with speech-to-text pipelines. The MIT license imposes no restrictions. No known vulnerabilities. Install it if you need this conversion; skip it if your input is already numeric.
Install
text2digits on PyPI
pip
pip install text2digitsuv
uv add text2digitspoetry
poetry add text2digitsInstalling text2digits
Before you install
Low friction: pure Python wheel with no runtime dependencies. Actively maintained as of 2026-04-28 with a recent commit history.
License in practice
MIT license permits unrestricted use, modification, and distribution in both open and closed projects with minimal attribution requirements.
Quickstart
pip install text2digits
from text2digits import text2digits
t2d = text2digits.Text2Digits()
result = t2d.convert("I am twenty nine years old")
print(result) # 'I am 29 years old'
Requires Python 3.7 or later.
Verify before relying
- Whether the package handles all edge cases in production speech-to-text pipelines beyond the documented examples.
- Performance characteristics when processing very long strings or batch operations.
- Whether the similarity_threshold spelling correction feature is suitable for your use case's accuracy requirements.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 108 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 242,404/month — #8,857 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: text2digits-0.1.2-py3-none-any.whl
Keywords: text2numbers, words2numbers, digits, numbers
Tags
More Linguistic packages
Detects and normalizes text encoding from…
permissive · top 100 on PyPI
tiktokentiktoken is a fast BPE tokenizer that converts…
permissive · top 1,000 on PyPI
chardetDetects character encoding and language in byte…
permissive · top 1,000 on PyPI
text-unidecodeConverts Unicode text to ASCII by…
copyleft · top 1,000 on PyPI
larkLark is a parsing library that builds abstract…
permissive · top 1,000 on PyPI
tree-sitterPython bindings to the tree-sitter parsing…
permissive · top 1,000 on PyPI
text2numConverts natural language number words into…
permissive · top 15,000 on PyPI
unicode-rbnfConverts numbers to spelled-out text in…
permissive · top 15,000 on PyPI
word2numberConverts written-out number words (like "twenty…
permissive · top 5,000 on PyPI
number-parserConverts numbers written in natural language…
permissive · top 15,000 on PyPI
kanjizeConverts between Japanese kanji number…
permissive · top 15,000 on PyPI
num2wordsConverts numbers to their word representations…
copyleft · top 5,000 on PyPI
indic-numtowordsConverts non-negative integers to their word…
permissive · top 15,000 on PyPI
inflectGenerates correct English plurals, singulars,…
permissive · top 1,000 on PyPI
sigfigRounds numbers by significant figures, decimal…
permissive · top 5,000 on PyPI
luhnGenerates and verifies Luhn check digits for…
permissive · top 15,000 on PyPI