-
Notifications
You must be signed in to change notification settings - Fork 0
05_Human
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 humanWhen set to True:
-
human.FEATURES.feature_spaceadd a space between the number and the unit -
human.FEATURES.feature_iecuse IEC (base 1024) instead of SI (base 1000) units and uses Ki, Mi, etc. prefixes for binary multiples of bytes -
human.FEATURES.feature_1024same asfeature_iecbut 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.
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"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"The throughput function converts a throughput value (in items per second) into a human-readable object.
print(human.throughput(123456789)) # "123.5Mit/s"Powered by caffeine and uv.
MIT license.