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 2.7+ or 3.5+

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.0.9.tar.gz (12.8 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.0.9-py2.py3-none-any.whl (9.0 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: humanreadable-0.0.9.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

File hashes

Hashes for humanreadable-0.0.9.tar.gz
Algorithm Hash digest
SHA256 3504cfd55265660d09e0f527570296f6bf7924a78f97e46e920c9566968c290d
MD5 5f96b13903e769b8e166837fbc4c40f0
BLAKE2b-256 4b12302bd2bb8acb824caf342f4cc89ee3be93bb7d402f013f1ae74f4c804c0f

See more details on using hashes here.

File details

Details for the file humanreadable-0.0.9-py2.py3-none-any.whl.

File metadata

  • Download URL: humanreadable-0.0.9-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

File hashes

Hashes for humanreadable-0.0.9-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 51780390df8a1a158a12c0e6814d2e99395a58947a21cd4a61e1302440820bcc
MD5 947334b4720ae2fee2ff69c0f3c1ca63
BLAKE2b-256 dd4a5a98ffe14f91f4475be7fa40147fe580528a8a4ab6cad757f45ba442923d

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