HWP stores almost every measurement (page width, margins, line spacing, font size, cell width) in an internal unit called HWPUNIT. The conversion table is:
User unit
HWPUNIT
1 mm
283 HWPUNIT
1 cm
2,834 HWPUNIT
1 inch
7,200 HWPUNIT
1 pt
100 HWPUNIT
Nobody wants to write Height = 1200 # 12pt in a script. The hwpapi.units module holds both directions of the conversion plus a string parser.
The five entry points
from hwpapi import units as U# → HWPUNIT (int)U.mm(210) # A4 widthU.cm(21.0) # same, different unitU.inch(8.27) # same, imperialU.pt(12) # 12pt font# HWPUNIT → user unit (float)U.to_mm(59430) # ≈ 210.0U.to_cm(59430) # ≈ 21.0U.to_inch(59430) # ≈ 8.27U.to_pt(1200) # 12.0# String parser — accepts "210mm" / "21cm" / "8.27in" / "12pt"U.parse("210mm")U.parse("12pt")
1200
U.parse is the most general — use it when you’re accepting a measurement from the user (CLI arg, config file, YAML) and want to stay unit-agnostic. It returns HWPUNIT as int.