easyword2num
easyword2num is a Python library that converts English words representing numbers into their numerical values. It supports large numbers, fractions, decimals, negative numbers, and mixed decimal-unit expressions.
Install
pip install easyword2num
Usage
from easyword2num import word2num
# Basic usage
number = word2num("seven million three thousand and four point five")
print(number) # Output: 7003004.5
# Handles negative numbers
number = word2num("negative sixteen")
print(number) # Output: -16
# Fractions
number = word2num("one fifth")
print(number) # Output: 0.2
# Decimals
number = word2num("two point three")
print(number) # Output: 2.3
# Mixed decimal-unit expressions
number = word2num("1.2 million")
Handling Numerical Sequences
By default, word2num does not interpret numerical sequences like "twenty nineteen" as 2019. To enable this behavior, set the allow_numerical_sequences parameter to True.
number = word2num("twenty nineteen", allow_numerical_sequences=True)
print(number) # Output: 2019
Error Handling
If the input string cannot be interpreted as a number, a UninterpretableNumberError is raised.
from easyword2num import word2num, UninterpretableNumberError
try:
number = word2num("invalid input")
except UninterpretableNumberError as e:
print(f"Error: {e}")
Contributing
Contributions are welcome! If you encounter any issues or have suggestions for improvements, please open an issue or submit a pull request on GitHub.
Development Setup
If you use Poetry
poetry install
poetry run pytest
Otherwise...
python -m venv venv
source venv/bin/activate
pip install -r requirements-dev.txt
pip install -e .
pytest
License
This project is licensed under the MIT License.
Metadata
Release files for easyword2num 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| easyword2num-0.1.3.tar.gz | 8.0 kB | Without provenance | Details for easyword2num-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| easyword2num-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for easyword2num-0.1.3-py3-none-any.whl |
Total release size: 16.9 kB
Release files / easyword2num-0.1.3.tar.gz
| Download URL | easyword2num-0.1.3.tar.gz |
|---|---|
| Size | 8.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
90e37ae621ac0d88fbcbcc546606c2e3b83f7cf497249e14c449bdb8f775a646
|
|
BLAKE2b-256 checksum How to use checksums |
e68e9099139f99f7c66c9142e81362822e9c5d0b351b76075dc0b67322d90c51
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.11.1 Darwin/23.5.0
|
Release files / easyword2num-0.1.3-py3-none-any.whl
| Download URL | easyword2num-0.1.3-py3-none-any.whl |
|---|---|
| Size | 8.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
88f190794acd33dcc7f97482022ba20fbde97d5c15f6b0d3941e18380be1e4b8
|
|
BLAKE2b-256 checksum How to use checksums |
6ce425aeb73cd288e380b840cc0bc9541a3ad98c5a6144ee4384edeab7465367
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.11.1 Darwin/23.5.0
|
Security for easyword2num 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.