Skip to main content

num2words2 library - Convert numbers to words in multiple languages

PyPI version Python versions License Monthly downloads AUR version CI status Lint status Coverage

num2words2 converts numbers like 42 to words like forty-two across 120+ languages and 170+ locale codes (see REFERENCE.md for the full table), producing cardinals, ordinals, currency, year, fractions, bank-cheque format, and aviation/ICAO digit-by-digit phraseology.

It is a Rust port of the num2words conversion engine with a thin Python binder. Every conversion runs in a compiled Rust core (PyO3/abi3); Python only normalises the arguments and shapes the result. The output is byte-for-byte identical to the original pure-Python library — validated against a frozen ~150,000-case corpus — while running typically 4–12× faster, and up to 26× on some languages and 150× on string parsing (see Performance).

The project is hosted on GitHub, and the full documentation is available in the Wiki. Contributions are welcome.

Performance

Because the conversion engine is compiled Rust, num2words2 is several times faster than the original pure-Python num2words. Benchmarked against num2words 0.5.14, Apple M-series, nanoseconds per call:

Operation

original

num2words2

speedup

int → cardinal (8765)

24,384 ns

2,099 ns

11.6×

float → cardinal (1234.56)

33,107 ns

3,367 ns

9.8×

ordinal

24,969 ns

2,407 ns

10.4×

currency

32,518 ns

3,345 ns

9.7×

year

13,484 ns

1,434 ns

9.4×

string input ("1234")

335,862 ns

2,200 ns

152.6×

French cardinal

61,046 ns

2,359 ns

25.9×

German cardinal

63,046 ns

2,386 ns

26.4×

Russian cardinal

4,781 ns

1,001 ns

4.8×

The speedup is largest where the original does heavy Python-level parsing (string inputs) or deep recursion (French, German); it never comes at the cost of accuracy — output is byte-for-byte identical to the original across a frozen ~150,000-case corpus of cardinals, ordinals, currency, years, fractions, floats and strings.

Installation

Install from PyPI (Python 3.10+) — the wheel bundles the Python binder and the compiled Rust extension, built per platform:

pip install num2words2

Prebuilt wheels are published for:

  • Linux — x86_64 and aarch64 (manylinux2014)

  • macOS — Apple Silicon (arm64) and Intel (x86_64)

  • Windows — x86_64

On any other platform, pip falls back to the source distribution and builds the extension locally — this needs a stable Rust toolchain (rustup).

Slim vs. full wheels

num2words2 ships in two flavours:

  • slim (the PyPI default, ~2 MB) — everything except native language-detection. num2words_sentence(lang=None) auto-detect is disabled; pass an explicit lang and every converter works.

  • full (~140 MB) — embeds the lingua-rs models so num2words_sentence(lang=None) auto-detects the language natively. Full wheels are attached to each GitHub Releases entry; install one directly:

    pip install https://github.com/gladiaio/num2words2/releases/download/v1.0.18/num2words2-1.0.18-cp38-abi3-<platform>.whl

The compiled extension is distributed only through these wheels (it is not committed to the repository).

To build from source you need a stable Rust toolchain and maturin:

maturin build --release                        # full (bundles lingua models)
maturin build --release --no-default-features  # slim (~2 MB, no models)

Development Setup

The project uses pre-commit hooks to ensure code quality. To set up your development environment:

# Install pre-commit
pip install pre-commit

# Install the git hook scripts
pre-commit install

# Run hooks on all files (optional, useful for initial setup)
pre-commit run --all-files

This will automatically format and lint your code before each commit using:

  • black - code formatting

  • autoflake - removes unused imports and variables

  • isort - sorts imports

  • flake8 - style and quality checks

  • trailing-whitespace removal

  • end-of-file fixing

Testing

The library uses pytest for testing. First, install the development dependencies:

make dev-install

Then, you can run the test suite using several methods:

  • Run basic tests: This runs tests with your current Python environment.

    make test
  • Run with Tox: This runs tests against all supported Python versions, which is the standard for CI.

    tox

Generating End-to-End Tests with LLMs

The repository includes a powerful script to generate high-quality, realistic test cases using Large Language Models (LLMs). This helps ensure accuracy across multiple languages and complex scenarios.

What it does: The tests/scripts/generate_llm_tests.py script uses an LLM (like GPT-4o) to create sentences containing numbers, dates, and currencies, and then generates the expected word-for-word conversion.

Requirements:

  • An OpenAI API key. You must set it as an environment variable: export OPENAI_API_KEY='your-key-here'

How to Use:

To generate 10 new test sentences for French and Spanish, you can run:

python tests/scripts/generate_llm_tests.py --languages fr,es --samples 10

The new tests will be appended to tests/data/e2e_test_sentences.csv.

Key Options:

  • --languages: Comma-separated list of language codes (e.g., en_IN,de,it).

  • --samples: Number of samples to generate per language.

  • --mode: Use sentences for full sentences or numbers for direct number-to-word conversions.

  • --model: The OpenAI model to use (e.g., gpt-4o, gpt-4o-mini).

  • --output: Specify a different output file.

  • --overwrite: Overwrite the output file instead of appending.

This tool is essential for expanding test coverage and ensuring the library’s robustness.

Usage

Command line:

$ num2words2 10001
ten thousand and one
$ num2words2 24,120.10
twenty-four thousand, one hundred and twenty point one zero
$ num2words2 24,120.10 -l es
veinticuatro mil ciento veinte punto uno cero
$ num2words2 2.14 -l es --to currency
dos euros con catorce céntimos

In code there’s only one function to use:

>>> from num2words2 import num2words
>>> num2words(42)
'forty-two'
>>> num2words(42, to='ordinal')
'forty-second'
>>> num2words(42, lang='fr')
'quarante-deux'

Besides the numerical argument, there are two main optional arguments, to: and lang:

to: The converter to use. Supported values are:

  • cardinal (default)

  • ordinal

  • ordinal_num

  • year

  • currency

  • cheque (bank-cheque format, e.g. ONE AND 00/100 DOLLARS)

  • fraction (also used automatically for 'n/d' strings such as '1/3')

lang: The language code (default en). num2words2 supports 120+ languages and 170+ codes, including regional variants such as pt_BR, fr_BE, sr_Latn, zh_TW and the aviation/ICAO codes en_Aero_ICAO & co. For the live list, run:

num2words2 --list-languages

The full table with language names is in REFERENCE.md.

Codes are matched case-insensitively and hyphens are read as underscores. You can supply values like fr_FR; if the country doesn’t exist but the language does, the code will fall back to the base language (i.e. fr). If you supply an unsupported language, NotImplementedError is raised. Therefore, if you want to call num2words with a fallback, you can do:

try:
    return num2words(42, lang=mylang)
except NotImplementedError:
    return num2words(42, lang='en')

Additionally, some converters and languages support other optional arguments that are needed to make the converter useful in practice.

Wiki

For the full documentation, including installation, API details, CLI usage, supported locales, sentence conversion, currency handling, and migration guidance, please check the Wiki. Feel free to propose wiki enhancements.

History

num2words is based on an old library, pynum2word, created by Taro Ogawa in 2003. Unfortunately, the library stopped being maintained and the author can’t be reached. There was another developer, Marius Grigaitis, who in 2011 added Lithuanian support, but didn’t take over maintenance of the project.

Virgil Dupras from Savoir-faire Linux based himself on Marius Grigaitis’ improvements and re-published pynum2word as num2words.

Relationship to num2words

num2words2 is not a divergent fork. It is a Rust port of the num2words conversion engine with a Python binder, kept output-compatible with the original.

The original project’s issues and pull requests are actively monitored. Valid, relevant fixes and features are reviewed and then ported into this project’s Rust core, with byte-parity re-verified against the frozen corpus. num2words2 therefore tracks upstream improvements while delivering them natively — and several times faster.

Jean-Louis Queguiner

Metadata

Release files for num2words2 1.0.21

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for num2words2 1.0.21
File Size Uploaded Provenance Actions
num2words2-1.0.21.tar.gz 2.8 MB With provenance Details for num2words2-1.0.21.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for num2words2 1.0.21
File Actions
num2words2-1.0.21-cp38-abi3-win_amd64.whl CPython 3.8 abi3 Windows x86-64 Details for num2words2-1.0.21-cp38-abi3-win_amd64.whl
num2words2-1.0.21-cp38-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.8 abi3 Linux glibc 2.17+ x86-64 Details for num2words2-1.0.21-cp38-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
num2words2-1.0.21-cp38-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.8 abi3 Linux glibc 2.17+ ARM64 Details for num2words2-1.0.21-cp38-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
num2words2-1.0.21-cp38-abi3-macosx_11_0_arm64.whl CPython 3.8 abi3 macOS 11.0+ ARM64 Details for num2words2-1.0.21-cp38-abi3-macosx_11_0_arm64.whl
num2words2-1.0.21-cp38-abi3-macosx_10_12_x86_64.whl CPython 3.8 abi3 macOS 10.12+ x86-64 Details for num2words2-1.0.21-cp38-abi3-macosx_10_12_x86_64.whl

Total release size: 21.0 MB

Release files / num2words2-1.0.21.tar.gz

Download URL num2words2-1.0.21.tar.gz
Size 2.8 MB
Tags Source
SHA-256 checksum
How to use checksums
a1c57b15c257db6059a57f2293c3aa8d29b5e8d955c3bbcfe6deacff06b4dcdf
BLAKE2b-256 checksum
How to use checksums
467f96f60ad3091401205041c64679be2bdce639d01bbf48110c7567f4349b4d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / num2words2-1.0.21-cp38-abi3-win_amd64.whl

Download URL num2words2-1.0.21-cp38-abi3-win_amd64.whl
Size 4.1 MB
Tags CPython 3.8 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
99470993bd562f57b17a694e251380ee55a3c6731835fc1bc51161bdf161c7d6
BLAKE2b-256 checksum
How to use checksums
a4cc2b2361e52e3c60687c4e4bc2d81706fb4805b17079f305306e35ff438acd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / num2words2-1.0.21-cp38-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL num2words2-1.0.21-cp38-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 3.7 MB
Tags CPython 3.8 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
a8db28e6782d4f2776c2e9418cd63f11dc529ac4763692b4de6dc2b610aba494
BLAKE2b-256 checksum
How to use checksums
a989bb6235237a0370a431e152c827f6c08ce557b23144efb44bb5cb4eb80913
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / num2words2-1.0.21-cp38-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL num2words2-1.0.21-cp38-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 3.5 MB
Tags CPython 3.8 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
e24fc22041f7c02a355f044445d6ca49bbad2e8e395e529d7469f1ae0095c1bf
BLAKE2b-256 checksum
How to use checksums
79aae33fd0ec229b5159d06d54e6f1974b2f453be326309e24424f281b3edbd3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / num2words2-1.0.21-cp38-abi3-macosx_11_0_arm64.whl

Download URL num2words2-1.0.21-cp38-abi3-macosx_11_0_arm64.whl
Size 3.3 MB
Tags CPython 3.8 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
1ebe0195b382171aa6f671216fc48dbd6951287b3f057789d3ae577dcc65af77
BLAKE2b-256 checksum
How to use checksums
7b25e4f82a116e08cc691b7ecd01ac0516f84288c68fbc2311740cef98a6e886
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / num2words2-1.0.21-cp38-abi3-macosx_10_12_x86_64.whl

Download URL num2words2-1.0.21-cp38-abi3-macosx_10_12_x86_64.whl
Size 3.6 MB
Tags CPython 3.8 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
2fb9b10631369514f5a2d955c81a9d17193a589e7d524d721f38a37216ee0fc1
BLAKE2b-256 checksum
How to use checksums
231ab3e32d20dbb0b853bd3b4b8ab84a5839c24a4a9f44550bc7c29191c54750
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Security for num2words2 1.0.21

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.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for num2words2-1.0.21.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page