size - Helper Functions

  • Binary Helpers – Methods like kib(), mib(), gib(), tib(), pib(), eib(), zib(), and yib() return 1024-based unit calculations.
  • Decimal Helpers – Methods like b(), kb(), mb(), gb(), tb(), pb(), eb(), zb(), and yb() return 1000-based unit calculations.
  • Type Preservation – Preserves input types (accepts and returns int or float without casting) to avoid arithmetic precision loss.
Signature
sizelib.size.<helper>(value: int | float) -> int | float

Binary Helpers (Base 2 / 1024)

Helper MethodBaseMultiplier ScaleValue (e.g. for input 1)
size.b(value)BIN (2)11
size.kib(value)BIN (2)1,0241,024
size.mib(value)BIN (2)1,024^21,048,576
size.gib(value)BIN (2)1,024^31,073,741,824
size.tib(value)BIN (2)1,024^41,099,511,627,776
size.pib(value)BIN (2)1,024^51,125,899,906,842,624
size.eib(value)BIN (2)1,024^61,152,921,504,606,846,976
size.zib(value)BIN (2)1,024^71,180,591,620,717,411,303,424
size.yib(value)BIN (2)1,024^81,208,925,819,614,629,174,706,176

Decimal Helpers (Base 10 / 1000)

Helper MethodBaseMultiplier ScaleValue (e.g. for input 1)
size.b(value)DEC (10)11
size.kb(value)DEC (10)1,0001,000
size.mb(value)DEC (10)1,000^21,000,000
size.gb(value)DEC (10)1,000^31,000,000,000
size.tb(value)DEC (10)1,000^41,000,000,000,000
size.pb(value)DEC (10)1,000^51,000,000,000,000,000
size.eb(value)DEC (10)1,000^61,000,000,000,000,000,000
size.zb(value)DEC (10)1,000^71,000,000,000,000,000,000,000
size.yb(value)DEC (10)1,000^81,000,000,000,000,000,000,000,000
size API - Basic Usage
from sizelib import size

# Define constraints using binary (base 2) or decimal (base 10) 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)
size API - Variables & Expressions
from sizelib import size

# Variables and expressions are fully supported
limit = 2
custom_limit = size.gib(limit)   # 2 GiB (2147483648 bytes)
size API - Type Preservation
from sizelib import size

# Input types (int/float) are dynamically preserved
MAX_UPLOAD_SIZE = size.mib(10)
print(MAX_UPLOAD_SIZE)           # Output: 10485760
print(type(MAX_UPLOAD_SIZE))     # Output: <class 'int'>

BUFFER_SIZE = size.kb(1.5)
print(BUFFER_SIZE)               # Output: 1500.0
print(type(BUFFER_SIZE))         # Output: <class 'float'>