Registry / serialization / number-parser

number-parser

JSON →
library0.3.2pypypi✓ verified 20d ago

number-parser is a Python library designed to convert numbers written in natural language into their equivalent numeric forms. It supports cardinal numbers in English, Hindi, Spanish, Ukrainian, and Russian, and also handles ordinal numbers and simple fractions in English. The current version is 0.3.2, and it maintains an active, though somewhat irregular, release cadence with several updates in early 2023.

pip install number-parser
INSTALL
IMPORT
SIG · NUMBER-PARSER
N
number-parser
serializationpythonv0.3.2
Install
1.9s avg
Import
16ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.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.95 runs
installs and imports cleanly · install 0.0s · import 0.018s · 19.1MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.9s · import 0.014s · 20MB
17MB installed
● package 17MB
Code
Verified usage

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

parse
from number_parser import parse
from number_parser.parser import parse
An import bug was fixed in v0.3.2; direct import from `number_parser` is the correct and stable path.
parse_number
from number_parser import parse_number
parse_ordinal
from number_parser import parse_ordinal
Supports English only.
parse_fraction
from number_parser import parse_fraction
Supports English only.

Demonstrates how to use `parse` for in-place number conversion within a string and `parse_number` for converting a standalone number written in words.

from number_parser import parse # Convert numbers in a sentence text = "I have two hats and thirty seven coats." parsed_text = parse(text) print(f"Original: {text}\nParsed: {parsed_text}") # Convert a single number in words number_in_words = "two thousand and twenty" parsed_number = parse_number(number_in_words) print(f"Number '{number_in_words}' parsed to: {parsed_number}")
Debug
Known issues
breakingPrior to version 0.3.2, users might have encountered an import bug (#91), which could lead to incorrect or failed imports of the parsing functions. This was fixed in version 0.3.2.
fix
Upgrade to number-parser >= 0.3.2. Ensure imports are directly from `number_parser` (e.g., `from number_parser import parse`) and not from internal modules like `number_parser.parser`.
affects: <0.3.2
gotchaInconsistent whitespace handling around sentence separators following numbers was an issue in versions prior to 0.3.1, potentially affecting parsing accuracy in specific contexts.
fix
Upgrade to number-parser >= 0.3.1 to benefit from the fix for inconsistent whitespace handling.
affects: <0.3.1
gotchaThe library's language support is granular: cardinal numbers are supported in multiple languages, but ordinal numbers and simple fractions are currently supported only for English. Attempting to parse non-English ordinals or fractions might yield unexpected results or errors.
fix
Consult the documentation for specific language support for each parsing function (e.g., `parse_ordinal` and `parse_fraction` are English-only). Ensure your input language matches the supported features.
affects: All versions
gotchaParsing natural language numbers can be inherently ambiguous, especially across different locales and contexts (e.g., 'one hundred thousand' vs. 'one, hundred thousand'). While the library aims for robust parsing, complex or unusual phrasing might not always be interpreted as expected.
fix
Test the library with a representative sample of your natural language number inputs. Be mindful of potential ambiguities and, if necessary, preprocess inputs or provide clearer phrasing.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'number_parser'
The `number-parser` library is not installed in the current Python environment or there's a typo in the import statement.
fix
Ensure the library is installed using pip: `pip install number-parser`. Then, import correctly as `from number_parser import parse` (note the underscore in `number_parser`).
parse_number('not_a_number')
The `parse_number` function is designed to convert a single number written in words (e.g., 'two thousand') to its integer form. Providing a string that does not represent a valid number in this format will result in `None` being returned, which users might perceive as an error if they expect an exception or a default numeric value.
fix
Check the return value of `parse_number` for `None` to handle unparseable input gracefully. For parsing numbers embedded in text, use the `parse` function instead. Example: `result = parse_number('not_a_number')` then `if result is None: print('Input could not be parsed.')`
AttributeError: module 'number_parser' has no attribute 'parse_string'
Users might guess function names based on common parsing patterns or misremember the API. The `number-parser` library uses `parse`, `parse_number`, `parse_ordinal`, and `parse_fraction` for its core functionalities, not `parse_string`.
fix
Refer to the official documentation or examples for the correct function names. For general string parsing, use `number_parser.parse()`. For single number parsing, use `number_parser.parse_number()`.
number-parser 'language not supported'
While `number-parser` supports several languages (English, Hindi, Spanish, Ukrainian, and Russian), attempting to use an unsupported language code with functions that accept a `language` parameter (e.g., `parse_number('one', language='french')`) will lead to incorrect parsing or unexpected behavior as the library will default to English or fail to recognize numbers in the unsupported language.
fix
Ensure that the `language` parameter is set to one of the currently supported locales ('en', 'hi', 'es', 'uk', 'ru'). If a language is not supported, the library may not be suitable for that specific use case.
Upgrade
Version history
0.3.2latest on PyPI · released Mar 28, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources