A comprehensive Python library for parsing and converting numbers between numeric, word, and ordinal formats.
Project description
numbr
A lightweight NLP-focused Python toolkit for recognising, parsing, and transforming numbers expressed in natural-language or symbolic form.
It handles everything from “forty-two” → 42 to “Ⅳ” → “fourth” in a single call.
✨ Key capabilities
| Task | Example in | Example out | Function |
|---|---|---|---|
| Spell-out → digits | "one hundred sixty-seven" |
167 |
wordsToInt |
| Digits → words | 19007 |
"nineteen thousand seven" |
intToWords |
| Any form → type detection | "3rd" |
"Ordinal Number" |
Type |
| Cross-form casting | "third" → "3" |
"third" |
Cast("third", "Cardinal Number") |
| Roman → integer | "MCMXCIV" |
1994 |
romanToInt |
| Batch extraction | "He scored twenty-one of 34 attempts" |
[21, 34] |
extractNumericValue |
(full API listed below)
🔧 Installation
pip install numbr
# or install from source
pip install git+https://github.com/cedricmoorejr/numbr.git
🚀 Quick start
import numbr
numbr.Type("forty-ninth")
# → 'Ordinal Word'
numbr.Cast("forty-ninth", target="Ordinal Number")
# → '49th'
numbr.Cast(512, target="Ordinal Word")
# → 'five hundred twelve th'
🧰 Public API Overview
numbr exposes a clean, top-level API designed for simplicity and readability.
All functions listed below are available directly via:
import numbr
numbr.Type("twenty-first")
numbr.Cast("Ⅳ", target="Ordinal Word")
No internal modules need to be accessed directly — everything is exposed at the package root.
1. High-Level Helpers
| Helper | Purpose |
|---|---|
Type(value) |
Detect and return the representation category of value — e.g., "Cardinal Word", "Ordinal Number", etc. |
Cast(value, target, *, as_str=False) |
Convert value to a target representation and optionally return it as a string. |
2. Core Conversion Functions
These functions handle numeric parsing, word formatting, Roman numeral conversion, and formatting:
wordsToInt,ordinalWordsToInt,stringToIntintToWords,intToOrdinalWordsordinalSuffix,stripOrdinalSuffixromanToInt,romanToWordsinsertSep,formatDecimal,extractNumericValue
3. Cross-Type Shorthands
These helpers provide direct one-step conversions between common forms:
cardinalWordToOrdinalNumordinalNumToCardinalWordordinalWordToCardinalNum- ...and many more.
Use these when you know the source and target types and want to avoid an intermediate call to Cast.
📝 Roadmap
- Locale & language plugins (FR, DE…)
- Currency-aware formatting
- CLI utility
📄 License
This project is licensed under the MIT License. See the LICENSE file for details.
🙌 Contributing
Issues, pull-requests and feature ideas are very welcome to improve numbr!
Clone the repo, create a branch, add tests, and open a PR.
Happy number-crunching!
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file numbr-2.0.5.tar.gz.
File metadata
- Download URL: numbr-2.0.5.tar.gz
- Upload date:
- Size: 25.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8176bddf859ab2b3ebd08a00c48aae76e3a05aac63cd0a1ee629b3c641fb192
|
|
| MD5 |
cac8091dcd515f65fab313188faaa5c8
|
|
| BLAKE2b-256 |
c812e8b3202c6919d91d575aef6542064761fbd1810f5b47b271a8e10d2d5400
|
File details
Details for the file numbr-2.0.5-py3-none-any.whl.
File metadata
- Download URL: numbr-2.0.5-py3-none-any.whl
- Upload date:
- Size: 25.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2253935eb49fd1535374e6f5629ceb93b49756ba936f53770ccec6842ee41fed
|
|
| MD5 |
73766d7d2cf7a8b5af87f2236269ff4c
|
|
| BLAKE2b-256 |
2f0475692f006a8b0df3b0001cdbc539b7f55c255e6e8739ffed8ccda21a6d76
|