Registry / ai-ml / text2num

text2num

JSON →
library3.0.2pypypi✓ verified 86d ago

text2num (v3.0.1) is an actively maintained Python library designed to parse and convert numbers expressed in natural language words from French, Spanish, English, Portuguese, German, Dutch, or Italian into their digit representations. It handles both integer parsing (`text2num`) and detection/transcription of cardinal, ordinal, and decimal numbers within a text stream (`alpha2digit`). The library is regularly updated and recently underwent a significant rewrite with a Rust backend.

pip install text2num
INSTALL
IMPORT
SIG · TEXT2NUM
T
text2num
ai-mlpythonv3.0.2
Install
1.5s avg
Import
11ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.0.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.012s · 19.2MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.5s · import 0.006s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

text2num
from text_to_num import text2num
from text2num import text2num
The top-level package name on PyPI is 'text2num', but the Python module to import from is 'text_to_num'.
alpha2digit
from text_to_num import alpha2digit
from text2num import alpha2digit
The top-level package name on PyPI is 'text2num', but the Python module to import from is 'text_to_num'.

The `text2num` function converts a full number phrase into an integer, while `alpha2digit` finds and transcribes all numbers (cardinals, ordinals, decimals) within a longer text. Both require specifying the language code (e.g., 'en', 'fr', 'es').

from text_to_num import text2num, alpha2digit # Convert a number expressed in words to its digit representation num_en = text2num("fifty-one million five hundred seventy-eight thousand three hundred two", "en") print(f"English number: {num_en}") # Expected: 51578302 num_fr = text2num('quatre-vingt-quinze', "fr") print(f"French number: {num_fr}") # Expected: 95 # Find and transcribe all numbers (cardinals, ordinals, decimals) in a text text_en = "On May twenty-third, I bought twenty-five cows, twelve chickens and one hundred twenty five point five kg of potatoes." alphad_en = alpha2digit(text_en, "en") print(f"Processed English text: {alphad_en}") # Expected: 'On May 23rd, I bought 25 cows, 12 chickens and 125.5 kg of potatoes.' text_es = "Compramos veinticinco vacas, doce gallinas y ciento veinticinco coma cuarenta kg de patatas." alphad_es = alpha2digit(text_es, "es") print(f"Processed Spanish text: {alphad_es}") # Expected: 'Compramos 25 vacas, 12 gallinas y 125,40 kg de patatas.'
Debug
Known issues
breakingVersion 3.0.0 was a complete rewrite, transitioning from a pure Python implementation (v2.x) to a Rust backend. This introduced several backward incompatible changes.
fix
Review the official documentation for v3.x to understand the new API, especially for `alpha2digit` and language support. If encountering issues, consider pinning to `text2num<3.0.0` if V2.x behavior is required.
affects: >=3.0.0
breakingSupport for signed numbers was dropped in version 3.x, as the feature was previously broken. The library now focuses on positive numbers.
fix
Handle negative number parsing externally if your application requires it. The library will not automatically convert 'minus five' to -5.
affects: >=3.0.0
breakingThe signature of the `alpha2digit` function changed in v3.x; the `threshold` optional parameter now applies to both ordinals and cardinals, instead of separate parameters.
fix
Update calls to `alpha2digit` to use the unified `threshold` parameter. Consult the v3.x documentation for its usage.
affects: >=3.0.0
gotchaThe Russian and Catalan languages, which were supported in previous 2.x versions, have not yet been fully ported to the 3.x Rust-based backend.
fix
Avoid using Russian ('ru') or Catalan ('ca') language codes with v3.x for critical applications, or pin to a v2.x version if these languages are essential. Check the latest release notes for updates on their support.
affects: >=3.0.0
Errors
Common errors & fixes
ImportError: cannot import name 'text2num' from 'text2num'
Attempting to import from the PyPI package name (`text2num`) instead of the actual module name (`text_to_num`).
fix
Change your import statement to `from text_to_num import text2num` or `from text_to_num import alpha2digit`.
ValueError: invalid literal for text2num: 'thousand thousand and two hundreds'
The input string does not represent a valid single number for parsing by `text2num`, or contains ambiguous/malformed numerical phrases.
fix
Ensure the input to `text2num` is a well-formed phrase representing a single number. For complex sentences with multiple numbers or non-standard phrasing, use `alpha2digit` which is designed for broader text transcription, or pre-process the input to isolate valid number phrases.
Upgrade
Version history
3.0.2latest on PyPI · released May 27, 2026
Audit
Dependencies
maturinoptionalBuild dependency for Rust backend; not a runtime dependency for users installing pre-compiled wheels.
Agent activity
27 hits · last 30 days
node
24
OpenAI (training)
1
Resources
text2num — pip install text2num · libregistry