Sizelib
sizelib is a lightweight, type-safe Python Library for working with and humanizing file sizes, time durations, frequencies, and data transfer rates. It offers clean, type-preserving unit helpers (supporting both int and float) and loop-based human-readable string conversions.
✳️ SDK
Installation
pip install sizelib
# or
uv add sizelib
Size Helper Functions
from sizelib import size
# Define constraints using binary (base 2 / 1024) or decimal (base 10 / 1000) helper methods
MAX_UPLOAD_SIZE = size.mib(10) # 10 MiB (10485760 bytes)
CACHE_LIMIT = size.gib(2) # 2 GiB (2147483648 bytes)
USER_QUOTA = size.gb(50) # 50 GB (50000000000 bytes)
# Variables, expressions, and type preservation (int/float) are supported
limit = 2
custom_limit = size.gib(limit) # 2 GiB (2147483648 bytes)
print(type(size.mib(10))) # Output: <class 'int'>
print(type(size.kb(1.5))) # Output: <class 'float'>
Humanize Byte Sizes (human_size)
from sizelib import human_size, size
# Default binary formatting (base 2 / 1024)
print(human_size(10485760)) # Output: 10 MiB
print(human_size(size.gib(2.5))) # Output: 2.50 GiB
# Decimal formatting (base 10 / 1000)
print(human_size(size.gb(50), base=10)) # Output: 50 GB
Time Helper Functions
from sizelib import time
# Define time constraints cleanly in seconds (supports ms, s, m, h, d, w, m28..m31, y, ly)
TIMEOUT = time.s(30) # 30 s
CACHE_TTL = time.m(15) # 900 s
TOKEN_EXPIRY = time.h(2) # 7200 s
FEB_NON_LEAP = time.m28(1) # 2419200 s (28 days)
# Variables, expressions, and type preservation (int/float) are supported
limit = 5
custom_timeout = time.m(limit) # 300 s
print(type(time.s(30))) # Output: <class 'int'>
print(type(time.s(1.5))) # Output: <class 'float'>
Humanize Times (human_time)
from sizelib import human_time, time
# Duration formatting across ms, s, m, h, d, w
print(human_time(0.005)) # Output: 5 ms
print(human_time(time.s(45))) # Output: 45 s
print(human_time(time.m(90))) # Output: 1.50 h
# Auto-rounds and formats fractional durations up to 2 decimal places
print(human_time(time.h(2.5))) # Output: 2.50 h
Frequency Helper Functions
from sizelib import freq
# Define frequency constraints cleanly in Hz (supports hz, khz, mhz, ghz, thz, phz, ehz, zhz, yhz)
CPU_BASE_CLOCK = freq.ghz(3.2) # 3.2 GHz (3200000000.0 Hz)
RAM_SPEED = freq.mhz(3200) # 3200 MHz (3200000000 Hz)
AUDIO_SAMPLE_RATE = freq.khz(44.1) # 44.1 kHz (44100.0 Hz)
# Variables, expressions, and type preservation (int/float) are supported
multiplier = 4.5
custom_clock = freq.ghz(multiplier) # 4.5 GHz (4500000000.0 Hz)
print(type(freq.mhz(800))) # Output: <class 'int'>
print(type(freq.ghz(4.8))) # Output: <class 'float'>
Humanize Frequencies (human_freq)
from sizelib import freq, human_freq
# Frequency formatting across Hz through YHz
print(human_freq(44100)) # Output: 44.10 kHz
print(human_freq(freq.mhz(800))) # Output: 800 MHz
print(human_freq(freq.ghz(3.2))) # Output: 3.20 GHz
print(human_freq(freq.thz(1.5))) # Output: 1.50 THz
Rate Helper Functions
from sizelib import rate
# Define bandwidth and bitrate constraints cleanly (supports b_s, kib_s..yib_s, kb_s..yb_s, bps, kibps..yibps, kbps..ybps)
NETWORK_BANDWIDTH = rate.mbps(100) # 100 Mbps (100000000 bits/s)
BUFFER_RATE = rate.mibps(50) # 50 Mibps (52428800 bits/s)
INTERNET_SPEED = rate.gbps(1) # 1 Gbps (1000000000 bits/s)
DOWNLOAD_SPEED = rate.mb_s(12.5) # 12.5 MB/s (12500000 bytes/s)
DISK_WRITE_RATE = rate.mib_s(500) # 500 MiB/s (524288000 bytes/s)
`Humanize Rates (human_rate)`
```python
from sizelib import human_rate, rate
# Default binary formatting (base 2 / 1024)
print(human_rate(10485760)) # Output: 10 MiB/s
print(human_rate(rate.gib_s(2.5))) # Output: 2.50 GiB/s
# Decimal formatting (base 10 / 1000)
print(human_rate(20000000000, base=10)) # Output: 20 GB/s
print(human_rate(rate.kb_s(5), base=10)) # Output: 5 KB/s
# Decimal bit rate formatting (bits=True)
print(human_rate(rate.mbps(100), bits=True)) # Output: 100 Mbps
print(human_rate(rate.gbps(1.5), bits=True)) # Output: 1.50 Gbps
# Binary bit rate formatting (bits=True, base=2)
print(human_rate(rate.mibps(2), base=2, bits=True)) # Output: 2 Mibps
✳️ Features
| FEATURE | DESCRIPTION |
|---|---|
| Size Helpers | Standardized functions for all major divisions (kb, mb, gb, tb, pb, eb, zb, yb, kib, mib, gib, tib, pib, eib, zib, yib) |
| Time Helpers | Clean scaling for duration units (ms, s, m, h, d, w, m28, m29, m30, m31, y, ly) |
| Frequency Helpers | Clean scaling for frequency units (hz, khz, mhz, ghz, thz, phz, ehz, zhz, yhz) |
| Rate Helpers | Clean scaling for data transfer rate units (b_s, kib_s..yib_s, kb_s..yb_s, bps, kibps..yibps, kbps..ybps) |
| Type Preservation | Dynamically maintains input types (returns int/floats accordingly) |
| Custom Bases | Support for both binary (base=2 / 1024) and decimal (base=10 / 1000) formats |
| Ultra Minimalism | Zero external dependencies with an optimized, lightweight iteration algorithm |
✳️ Architecture
| # | COMPONENT | DESCRIPTION | STACK |
|---|---|---|---|
| 1️⃣ | Sizelib SDK | Python library for size, time, frequency & rate calculations and humanization | Python |
| 2️⃣ | Sizelib Docs | Official documentation & web interface | Next.js, Tailwind, Vercel |
Made with 📄 by Saptarshi Roy
Metadata
Release files for sizelib 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sizelib-0.4.0.tar.gz | 9.9 kB | Without provenance | Details for sizelib-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sizelib-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for sizelib-0.4.0-py3-none-any.whl |
Total release size: 18.2 kB
Release files / sizelib-0.4.0.tar.gz
| Download URL | sizelib-0.4.0.tar.gz |
|---|---|
| Size | 9.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8c64d0cbeb6950c25534c8aacba9a8bdb5ab5fd4f9d767079f7401bcd98a5c72
|
|
BLAKE2b-256 checksum How to use checksums |
1654ca55632ae175c7d68acfe6c042cc4e82a19f3eb52ab42361758eca6f8a66
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / sizelib-0.4.0-py3-none-any.whl
| Download URL | sizelib-0.4.0-py3-none-any.whl |
|---|---|
| Size | 8.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b62f37aaeaf20662d19bcc6d8c922ae49d68e16fe3449d93a8316ecdc950fa35
|
|
BLAKE2b-256 checksum How to use checksums |
48297d680de659d6749a09cb5493d4499406a88a30847c17d54823721201eeac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for sizelib 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.