Sizelib
sizelib is a lightweight, type-safe Python Library for working with and humanizing file sizes, time durations, and frequencies. 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
✳️ 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) |
| 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 calculations and humanization | Python |
| 2️⃣ | Sizelib Docs | Official documentation & web interface | Next.js, Tailwind, Vercel |
Made with 📄 by Saptarshi Roy
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 sizelib-0.3.0.tar.gz.
File metadata
- Download URL: sizelib-0.3.0.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fcefec275064275e2de06f266879521cda7de847a59c99c080d79a6d5e201bee
|
|
| MD5 |
7a16d1da8adbc375e2d0c8ebd3595668
|
|
| BLAKE2b-256 |
3071397c2ecfff5b23cafd5f57d3fa83ba07ea2cdda44692821b3d737156f2e1
|
File details
Details for the file sizelib-0.3.0-py3-none-any.whl.
File metadata
- Download URL: sizelib-0.3.0-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
640076c8b97839173ba7eb8a16322c2ec67222864c8bb6729e0ec5a88b329c70
|
|
| MD5 |
c34378297861ca1c489d98990295984c
|
|
| BLAKE2b-256 |
c8542369aeb991a2f9ae593892458256e3f1d987e360403bcac3519260a7a9c6
|