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.
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
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 |
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
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file humanreadable-0.4.1.tar.gz.
File metadata
- Download URL: humanreadable-0.4.1.tar.gz
- Upload date:
- Size: 18.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4350eba873975939dc65bd6a64b1ad885418ff58d9c6693435507382d42a22f3
|
|
| MD5 |
27150b67417fbe50f6b4f27f7d3e0e68
|
|
| BLAKE2b-256 |
407a11b6b14db6f0525ef9052016fa1790fda09fff3b7a24f142213d90113230
|
Provenance
The following attestation bundles were made for humanreadable-0.4.1.tar.gz:
Publisher:
publish.yml on thombashi/humanreadable
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
humanreadable-0.4.1.tar.gz -
Subject digest:
4350eba873975939dc65bd6a64b1ad885418ff58d9c6693435507382d42a22f3 - Sigstore transparency entry: 206594879
- Sigstore integration time:
-
Permalink:
thombashi/humanreadable@69f67b886f41ece0f23ae1d53de9473b47577ba1 -
Branch / Tag:
refs/tags/v0.4.1 - Owner: https://github.com/thombashi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@69f67b886f41ece0f23ae1d53de9473b47577ba1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file humanreadable-0.4.1-py3-none-any.whl.
File metadata
- Download URL: humanreadable-0.4.1-py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1341e7b52ab2b884aebc7bc41b2bb4c6bd47b9719598648e11e133e6254aeb4f
|
|
| MD5 |
bd2e7ddf4a74bbcb91f94232a990094c
|
|
| BLAKE2b-256 |
da73e3af126a1399f99e55cc982a486a25173700b3a3e117165767ecd5cab5a8
|
Provenance
The following attestation bundles were made for humanreadable-0.4.1-py3-none-any.whl:
Publisher:
publish.yml on thombashi/humanreadable
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
humanreadable-0.4.1-py3-none-any.whl -
Subject digest:
1341e7b52ab2b884aebc7bc41b2bb4c6bd47b9719598648e11e133e6254aeb4f - Sigstore transparency entry: 206594881
- Sigstore integration time:
-
Permalink:
thombashi/humanreadable@69f67b886f41ece0f23ae1d53de9473b47577ba1 -
Branch / Tag:
refs/tags/v0.4.1 - Owner: https://github.com/thombashi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@69f67b886f41ece0f23ae1d53de9473b47577ba1 -
Trigger Event:
push
-
Statement type: