skillfed

text2digits

A small library to convert text numbers to digits in a string

text2digits v0.1.2 242.4K downloads/30d#8,857 on PyPI67
Permissive license MIT Active released

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 text2digits

uv

uv add text2digits

poetry

poetry add text2digits

Installing 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

License :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3

Tags

convert text numbers to digitsnumber words to numeralstext to number conversionwritten numbers parserspeech-to-text number cleanupordinal and cardinal conversionnatural language number parsing
nlpspeech-to-texttext-normalization

More Linguistic packages