Skip to main content

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.

PyPI package version https://img.shields.io/pypi/pyversions/humanreadable.svg Supported Python implementations Linux/macOS CI status https://img.shields.io/appveyor/ci/thombashi/humanreadable/master.svg?label=Windows%20CI Test coverage

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

Available units for humanreadable.Time
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
Available units for humanreadable.BitPerSecond
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 3.5+

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)

Uploaded source

Built Distribution

humanreadable-0.1.0-py3-none-any.whl (8.8 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page