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 text2numVerified import paths — ran on the pinned version, not inferred.
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').
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.
Handle negative number parsing externally if your application requires it. The library will not automatically convert 'minus five' to -5.
Update calls to `alpha2digit` to use the unified `threshold` parameter. Consult the v3.x documentation for its usage.
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.Change your import statement to `from text_to_num import text2num` or `from text_to_num import alpha2digit`.
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.