humanreadable

0.4.1 · active · verified Fri Apr 17

humanreadable is a Python library to convert human-readable values for sizes, times, and bit rates into other units. It supports various formats like '1MB', '1 day', or '100Mbps'. The current version is 0.4.1. Releases occur irregularly, often tied to Python version support updates and essential bug fixes.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import and use the `Size`, `Time`, and `BitsPerSecond` classes to parse human-readable strings and access their converted values, including basic arithmetic operations.

from humanreadable import Size, Time, BitsPerSecond

# Convert human-readable size to bytes, kilobytes, etc.
size_mb = Size("1.5 MB")
print(f"1.5 MB is {size_mb.byte} bytes")
print(f"1.5 MB is {size_mb.kbyte} KB")

# Convert human-readable time to seconds, minutes, hours, etc.
time_day = Time("2 days 3 hours")
print(f"2 days 3 hours is {time_day.hours} hours")
print(f"2 days 3 hours is {time_day.minutes} minutes")

# Convert human-readable bit rate to bits per second, kilobits per second, etc.
rate_gbps = BitsPerSecond("10 Gbps")
print(f"10 Gbps is {rate_gbps.bps} bits/second")
print(f"10 Gbps is {rate_gbps.giga_bps} Gbps")

# Perform arithmetic operations (available from v0.3.0+)
size_a = Size("10 MB")
size_b = Size("2048 KB") # 2MB
total_size = size_a + size_b
print(f"10 MB + 2048 KB = {total_size.mbyte} MB")

view raw JSON →