click_extra.humanize module¶
Human-readable rendering of machine values.
Formatters that turn raw numbers into the compact strings shown in terminal
output, tables and reports. The reverse direction, parsing a human-written
value back into a machine type, lives in click_extra.types (see
Duration).
- click_extra.humanize.format_size(size, *, units='iec', precision=1)[source]¶
Render a byte count as a compact, human-readable string.
- Parameters:
size (
float) – The number of bytes. A negative value keeps a leading-.units (
Literal['iec','si','jedec']) – The unit system to render in:iec(the default) for binary powers with the unambiguousKiB/MiBsymbols,sifor decimal powers withkB/MB, orjedecfor binary powers with the customary but impreciseKB/MB.precision (
int) – Number of fractional digits for every unit above bytes. A byte count is always rendered as a whole number.
- Return type:
- Returns:
The size followed by a space and its unit, like
1.5 KiB. The integer part is grouped with thousands separators.- Raises:
ValueError – If units is not a known unit system.
- click_extra.humanize.format_duration(duration)[source]¶
Render an elapsed duration compactly:
2.3s,1:05, then1:02:03.Below a minute the duration reads as one-decimal seconds (
2.3s). From a minute up it switches to a clock layout, growing an hours field only once it reaches an hour:1:05under an hour,1:02:03at or above.The reverse direction, parsing a human-written duration back into a
timedelta, lives inclick_extra.types(seeDuration).