Skip to main content

A library for manipulating well-formed Roman numerals.

Integers between 1 and 3,999 (inclusive) are supported. Numbers beyond this range will return an OutOfRangeError.

The classical system of roman numerals requires that the same character may not appear more than thrice consecutively, meaning that ‘MMMCMXCIX’ (3,999) is the largest well-formed Roman numeral. The smallest is ‘I’ (1), as there is no symbol for zero in Roman numerals.

Both upper- and lower-case formatting of roman numerals are supported, and likewise for parsing strings, although the entire string must be of the same case. Numerals that do not adhere to the classical form are rejected with an InvalidRomanNumeralError.

Example usage

Creating a roman numeral

from roman_numerals import RomanNumeral

num = RomanNumeral(16)
assert str(num) == 'XVI'

num = RomanNumeral.from_string("XVI")
assert int(num) == 16

Convert a roman numeral to a string

from roman_numerals import RomanNumeral

num = RomanNumeral(16)
assert str(num) == 'XVI'
assert num.to_uppercase() == 'XVI'
assert num.to_lowercase() == 'xvi'
assert repr(num) == 'RomanNumeral(16)'

Extract the decimal value of a roman numeral

from roman_numerals import RomanNumeral

num = RomanNumeral(42)
assert int(num) == 42

Invalid input

from roman_numerals import RomanNumeral, InvalidRomanNumeralError

num = RomanNumeral.from_string("Spam!")  # raises InvalidRomanNumeralError
num = RomanNumeral.from_string("CLL")  # raises InvalidRomanNumeralError
num = RomanNumeral(0)  # raises OutOfRangeError
num = RomanNumeral(4_000)  # raises OutOfRangeError

Licence

This project is licenced under the terms of either the Zero-Clause BSD licence or the CC0 1.0 Universal licence. See LICENCE.rst for the full text of both licences.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

roman_numerals_py-3.0.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

roman_numerals_py-3.0.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file roman_numerals_py-3.0.0.tar.gz.

File metadata

  • Download URL: roman_numerals_py-3.0.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for roman_numerals_py-3.0.0.tar.gz
Algorithm Hash digest
SHA256 91199c4373658c03d87d9fe004f4a5120a20f6cb192be745c2377cce274ef41c
MD5 49433988190ae02147a61c9a9f8a7686
BLAKE2b-256 9e789491ab144c9cb2d97aa74d6f632bd6f4be67957de03f945a23a67415d859

See more details on using hashes here.

Provenance

The following attestation bundles were made for roman_numerals_py-3.0.0.tar.gz:

Publisher: create-release.yml on AA-Turner/roman-numerals

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file roman_numerals_py-3.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for roman_numerals_py-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a1421ce66b3eab7e8735065458de3fa5c4a46263d50f9f4ac8f0e5e7701dd125
MD5 825ecbc430928154788f43ab4c02f9fe
BLAKE2b-256 27d0a3a2fed015e95b9e81619182adc472540f9786183febfaef8b7c5e909418

See more details on using hashes here.

Provenance

The following attestation bundles were made for roman_numerals_py-3.0.0-py3-none-any.whl:

Publisher: create-release.yml on AA-Turner/roman-numerals

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

4.1.0

2 files

4.0.0

2 files

3.1.0

2 files

This release

3.0.0 This release

2 files

2.0.0

2 files

1.0.0

2 files

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