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 human-readable values to other units.

PyPI package version https://img.shields.io/pypi/pyversions/humanreadable.svg Supported Python implementations CI status of Linux/macOS/Windows Test coverage

Supported Unites

  • time (days, hours, minutes, seconds, etc.)

  • bits per second

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 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

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

Project details


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.2.0.tar.gz (33.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

humanreadable-0.2.0-py3-none-any.whl (29.8 kB view details)

Uploaded Python 3

File details

Details for the file humanreadable-0.2.0.tar.gz.

File metadata

  • Download URL: humanreadable-0.2.0.tar.gz
  • Upload date:
  • Size: 33.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for humanreadable-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0bd84048b518aa62a4a6cf546d7c748324d8129ba0071cf502728629114bb544
MD5 475853b23b02edb121be2689879619c6
BLAKE2b-256 a5f7390b7d609b3000405f5b3bac62f9cb0cd1bcd8b97b92e8d9e4530edf6879

See more details on using hashes here.

File details

Details for the file humanreadable-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: humanreadable-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 29.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for humanreadable-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3aad2ed4352732f35879f8048fddd948b7b9b3995500e008e2b75fa334118e2e
MD5 f35678548182d42d7df983f624ef96ad
BLAKE2b-256 941a8eaa0a0933e43118aec6d1d1d5c906e507e08f7f5c9cf6992eac39f84ccc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page