roman-numerals-py
This package provides utilities for manipulating well-formed Roman numerals. It is currently at version 4.1.0 and is explicitly deprecated. Users are advised to switch to the `roman-numerals` package instead. The project seems to follow the release cadence of the main `roman-numerals` library.
Warnings
- breaking This package (`roman-numerals-py`) is deprecated. As of version 4.0.0, it functions solely as a meta-package that depends on `roman-numerals` and installs no modules itself. Direct usage should be migrated to `roman-numerals` to avoid future issues and leverage active development.
- breaking Version 4.0.0 dropped support for Python 3.9. Users on Python 3.9 or older will encounter compatibility issues.
- gotcha There is a common confusion between the PyPI package names `roman-numerals-py` and `roman-numerals`. While `roman-numerals-py` is deprecated and acts as a wrapper, `roman-numerals` is the active, standalone library providing the actual Roman numeral manipulation functionality.
Install
-
pip install roman-numerals-py -
pip install roman-numerals
Imports
- RomanNumeral
from roman_numerals import RomanNumeral
- InvalidRomanNumeralError
from roman_numerals import InvalidRomanNumeralError
- OutOfRangeError
from roman_numerals import OutOfRangeError
Quickstart
from roman_numerals import RomanNumeral, InvalidRomanNumeralError, OutOfRangeError
# Create a RomanNumeral from an integer
num_from_int = RomanNumeral(16)
print(f"Integer 16 as Roman: {num_from_int}") # Expected: XVI
# Create a RomanNumeral from a string
num_from_string = RomanNumeral.from_string("XVI")
print(f"Roman 'XVI' as Integer: {int(num_from_string)}") # Expected: 16
# Convert to uppercase/lowercase
print(f"'XVI' uppercase: {num_from_string.to_uppercase()}")
print(f"'XVI' lowercase: {num_from_string.to_lowercase()}")
# Handle invalid input
try:
RomanNumeral.from_string("Spam!")
except InvalidRomanNumeralError as e:
print(f"Caught expected error for 'Spam!': {e}")
try:
RomanNumeral(0)
except OutOfRangeError as e:
print(f"Caught expected error for 0: {e}")