Sizelib
sizelib is a lightweight, type-safe Python Library for working with and humanizing file sizes and time durations. 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
✳️ 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) |
| 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 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.2.3.tar.gz.
File metadata
- Download URL: sizelib-0.2.3.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5a53b22f5517ba80f2d96a6bc2f5fd06f7cab0b8bba70086cdeaa82d6ce244f
|
|
| MD5 |
0b6a97a14e31bf4bb0d89748b7edb8dd
|
|
| BLAKE2b-256 |
af130de7a3bd33eb61d15e4885b2b5650d9b716ccd92728db03f998c52d50411
|
File details
Details for the file sizelib-0.2.3-py3-none-any.whl.
File metadata
- Download URL: sizelib-0.2.3-py3-none-any.whl
- Upload date:
- Size: 5.5 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 |
f502bf0d0b1f91780ea8e3c0378100e26a8495d211b6ff00c322a2bfb62929af
|
|
| MD5 |
c1d48c2639380be7f681309792f14b7c
|
|
| BLAKE2b-256 |
055500260662f5f4089b69c981f036c93ab00a8de1dd51f8626cbb5176553b78
|