humanreadable is a Python library to convert from human-readable values to Python values.
Project description
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.
- 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
Dependencies
Python 2.7+ or 3.5+
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.0.8-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 575429dcf29ec05aef2583823f49a7e7e232acfd3d014f48dbadddb6d922682b |
|
MD5 | 54b43733ab427ba8cdbfec35cfbb462b |
|
BLAKE2b-256 | cb4a0f575a292e8b72fc548dbf6b40258936523e828376be95eab123a4d11b34 |