Skip to content

05_Human

Thomas Byr edited this page May 26, 2026 · 1 revision

Human measures and scales

  1. Counting
  2. Measuring durations
  3. Assessing throughputs

This nob.human module provides utilities for human-readable measures and scales. It is used internally in nob.time to provide human-readable durations, counts and throughputs.

You can customize the unit system and formats by using human.FEATURES:

from nob import human

When set to True:

  • human.FEATURES.feature_space add a space between the number and the unit
  • human.FEATURES.feature_iec use IEC (base 1024) instead of SI (base 1000) units and uses Ki, Mi, etc. prefixes for binary multiples of bytes
  • human.FEATURES.feature_1024 same as feature_iec but keeps the SI prefixes (k, M, G, etc.) instead of using the IEC ones (Ki, Mi, Gi, etc.)

The following functions all return an object. (Indirectly) Calling __str__ uses the .str() method which returns a human-readable string.

Counting

You can use count on any non-negative number (int or float) to get a human-readable version of it.

print(human.count(123456789))  # "123.5M"

Measuring durations

The duration function converts a time value (in seconds) into a human-readable object. The scale goes from ns (nanoseconds) to hours. Measuring durations outside of this range will result in the formatted string being off in some cases.

print(human.duration(123.456))  # "2:03.5"

Assessing throughputs

The throughput function converts a throughput value (in items per second) into a human-readable object.

print(human.throughput(123456789))  # "123.5Mit/s"

Clone this wiki locally