humanreadable is a Python library to convert from human-readable values to Python values.
Project description
humanreadable
Summary
humanreadable is a Python library to convert from human-readable values to other units.
Supported Unites
- time (days, hours, minutes, seconds, etc.)
- bit per seconds
Usage
Basic usages
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)) print("\n[Examples: humanreadable.BitPerSecond]") value = "1 Gbps" print("'{}' to Mbps -> {}".format(value, hr.BitPerSecond(value).mega_bps)) print("'{}' to Kbps -> {}".format(value, hr.BitPerSecond(value).kilo_bps)) print("'{}' to Kibps -> {}".format(value, hr.BitPerSecond(value).kibi_bps)) |
---|---|
Output: | [Examples: humanreadable.Time] '120 sec' to msecs -> 120000.0 '120 sec' to minutes -> 2.0 [Examples: humanreadable.BitPerSecond] '1 Gbps' to Mbps -> 1000.0 '1 Gbps' to Kbps -> 1000000.0 '1 Gbps' to Kibps -> 953674.31640625 |
Set default unit
Unit for an instance is determined by input value. If a valid unit 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/bit/s |
Kbps | [kK]bps/[kK]bit/s |
Kibps | [kK]ibps/[kK]ibit/s |
Mbps | [mM]bps/[mM]bit/s |
Mibps | [mM]ibps/[mM]ibit/s |
Gbps | [gG]bps/[gG]bit/s |
Gibps | [gG]ibps/[gG]ibit/s |
Tbps | [tT]bps/[tT]bit/s |
Tibps | [tT]ibps/[tT]ibit/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
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
humanreadable-0.1.0.tar.gz
(12.7 kB
view hashes)
Built Distribution
Close
Hashes for humanreadable-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c925e8d805d7a29ff089d11be92a5b80f4545e9e44b20e01d23a65b278a9b573 |
|
MD5 | d291173e454d20bf647dcabb1f981ab1 |
|
BLAKE2-256 | c20cbd7824b5b543eeccd62a3a391a01151b8a145be016ad8ac23eef1e1ed8a3 |