Skip to main content

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, stringToInt
  • intToWords, intToOrdinalWords
  • ordinalSuffix, stripOrdinalSuffix
  • romanToInt, romanToWords
  • insertSep, formatDecimal, extractNumericValue

3. Cross-Type Shorthands

These helpers provide direct one-step conversions between common forms:

  • cardinalWordToOrdinalNum
  • ordinalNumToCardinalWord
  • ordinalWordToCardinalNum
  • ...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

numbr-2.0.6.tar.gz (25.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

numbr-2.0.6-py3-none-any.whl (25.4 kB view details)

Uploaded Python 3

File details

Details for the file numbr-2.0.6.tar.gz.

File metadata

  • Download URL: numbr-2.0.6.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

Hashes for numbr-2.0.6.tar.gz
Algorithm Hash digest
SHA256 def83dce038b0fe93eeca07b6d7b6aeb88b9dec7a38f7e3bbd5096ce52dfad84
MD5 b7f9e5f34e78ae2f044186a490025abe
BLAKE2b-256 482908b5c01d4bd7bbcd5dfdaa03fee96a832efac0dfb68a4440eb01264236ba

See more details on using hashes here.

File details

Details for the file numbr-2.0.6-py3-none-any.whl.

File metadata

  • Download URL: numbr-2.0.6-py3-none-any.whl
  • Upload date:
  • Size: 25.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.8.5

File hashes

Hashes for numbr-2.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 2cadc6c3febe260adba64ca449b62a7be23fe5f00cb0d5be1c81c8227be42f96
MD5 d46643e7f791da509568551a0b784f30
BLAKE2b-256 89217ab1470ab5ea39a06f5ef4dfe055f15302b122e8326f2fd6f99e55b2f2e1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page