Skip to main content

humanreadable is a Python library to convert human-readable values to other units.

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

Convert a human-readable value to another unit

Sample Code:
import humanreadable as hr

print("\n[Examples: humanreadable.Time]")
value = "120 sec"
print(f"'{value}' to msecs -> {hr.Time(value).milliseconds}")
print(f"'{value}' to minutes -> {hr.Time(value).minutes}")

value = "12 min 40 sec"
print(f"'{value}' to seconds -> {hr.Time(value).seconds}")

print("\n[Examples: humanreadable.BitsPerSecond]")
value = "1 Gbps"
print(f"'{value}' to Mbps -> {hr.BitsPerSecond(value).mega_bps}")
print(f"'{value}' to Kbps -> {hr.BitsPerSecond(value).kilo_bps}")
print(f"'{value}' to Kibps -> {hr.BitsPerSecond(value).kibi_bps}")
Output:
[Examples: humanreadable.Time]
'120 sec' to msecs -> 120000.0
'120 sec' to minutes -> 2.0
'12 minutes 40 seconds' to seconds -> 760.0

[Examples: humanreadable.BitsPerSecond]
'1 Gbps' to Mbps -> 1000.0
'1 Gbps' to Kbps -> 1000000.0
'1 Gbps' to Kibps -> 976562.5

Convert a value to a human readable string

Sample Code:
import humanreadable as hr

t = hr.Time("400", default_unit=hr.Time.Unit.SECOND)
print(t.to_humanreadable())
print(t.to_humanreadable(style="short"))
Output:
6 minutes 40 seconds
6m 40s

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 unit 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.BitsPerSecond

Unit

Available unit specifiers (str)

Kbps

[kK]bps/[kK]bits?(/|\s?per\s?)(s|sec|second)

Kibps

[kK]ibps/[kK]ibits?(/|\s?per\s?)(s|sec|second)

Mbps

[mM]bps/[mM]bits?(/|\s?per\s?)(s|sec|second)

Mibps

[mM]ibps/[mM]ibits?(/|\s?per\s?)(s|sec|second)

Gbps

[gG]bps/[gG]bits?(/|\s?per\s?)(s|sec|second)

Gibps

[gG]ibps/[gG]ibits?(/|\s?per\s?)(s|sec|second)

Tbps

[tT]bps/[tT]bits?(/|\s?per\s?)(s|sec|second)

Tibps

[tT]ibps/[tT]ibits?(/|\s?per\s?)(s|sec|second)

bps

bps/bits?(/|\s?per\s?)(s|sec|second)

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

Uploaded Source

Built Distribution

humanreadable-0.4.0-py3-none-any.whl (32.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for humanreadable-0.4.0.tar.gz
Algorithm Hash digest
SHA256 2879a146f0602512addfcfba227956a3f1d23b99e9f938ff91b2085a170519ba
MD5 4e1d63f68352f13c345b58bb84b4edd3
BLAKE2b-256 f5d33990cc72903cc9e614f4699cb991f393b6691e57cc4d3609b36888665e63

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for humanreadable-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5b70257a8e88856f9b64a1f0a6fb7535c9002818465e298ca27d745b25e5675d
MD5 a8fc7553c5850e3f8d538d6153da0c0b
BLAKE2b-256 154b745e5a1aa266846df4216e84773bb77c48f95d8df6795adfdb2658afa4a3

See more details on using hashes here.

Supported by

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