humanreadable is a Python library to convert human-readable values to other units.
Project description
Summary
humanreadable is a Python library to convert human-readable values to other units.
Supported Unites
time (days, hours, minutes, seconds, etc.)
bits per second
Usage
Convert a human-readable value to another unit
- Sample Code:
import humanreadable as hr print("\n[Examples: humanreadable.Time]") value = "120 sec" print("'{}' to msecs -> {}".format(value, hr.Time(value).milliseconds)) print("'{}' to minutes -> {}".format(value, hr.Time(value).minutes)) value = "12 min 40 sec" print("'{}' to seconds -> {}".format(value, hr.Time(value).seconds)) print("\n[Examples: humanreadable.BitsPerSecond]") value = "1 Gbps" print("'{}' to Mbps -> {}".format(value, hr.BitsPerSecond(value).mega_bps)) print("'{}' to Kbps -> {}".format(value, hr.BitsPerSecond(value).kilo_bps)) print("'{}' to Kibps -> {}".format(value, hr.BitsPerSecond(value).kibi_bps))
- Output:
[Examples: humanreadable.Time] '120 sec' to msecs -> 120000.0 '120 sec' to minutes -> 2.0 '12 minutes 40 seconds' to seconds -> 760.0 [Examples: humanreadable.BitsPerSecond] '1 Gbps' to Mbps -> 1000.0 '1 Gbps' to Kbps -> 1000000.0 '1 Gbps' to Kibps -> 976562.5
Convert a value to a human readable string
- Sample Code:
import humanreadable as hr hr.Time("400", default_unit=hr.Time.Unit.SECOND).to_humanreadable()
- Output:
6 minutes 40 seconds
Set default unit
Unit for an instance is determined by input value. If a valid unit is not found, default_unit will be used for the instance (defaults to None).
- Sample Code:
import humanreadable as hr print(hr.Time("1", default_unit=hr.Time.Unit.SECOND))
- Output:
1.0 seconds
Units
Unit |
Available specifiers (str) |
---|---|
days |
d/day/days |
hours |
h/hour/hours |
minutes |
m/min/mins/minute/minutes |
seconds |
s/sec/secs/second/seconds |
milliseconds |
ms/msec/msecs/millisecond/milliseconds |
microseconds |
us/usec/usecs/microsecond/microseconds |
Unit |
Available specifiers (str) |
---|---|
bps |
bps/bits?/s |
Kbps |
[kK]bps/[kK]bits?/s |
Kibps |
[kK]ibps/[kK]ibits?/s |
Mbps |
[mM]bps/[mM]bits?/s |
Mibps |
[mM]ibps/[mM]ibits?/s |
Gbps |
[gG]bps/[gG]bits?/s |
Gibps |
[gG]ibps/[gG]ibits?/s |
Tbps |
[tT]bps/[tT]bits?/s |
Tibps |
[tT]ibps/[tT]ibits?/s |
Installation
Installation: pip
pip install humanreadable
Installation: apt (for Ubuntu)
sudo add-apt-repository ppa:thombashi/ppa sudo apt update sudo apt install python3-humanreadable
Dependencies
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for humanreadable-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e604bfad4c419cc6cf1c544ee192ffb711387a914fb897eaba615211c631e9cd |
|
MD5 | 527218ac197f1547fb28284b3e7c85a3 |
|
BLAKE2b-256 | 20c722087d17c84a893123864a74e17e50399fed53d7b49866784b5e3fc4f4a1 |