Skip to main content

📄
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.

🔗 PyPI Package  |  🆔 pip install sizelib or uv add sizelib


🐍 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 and expressions are fully supported
limit = 2
custom_limit = size.gib(limit)   # 2 GiB (2147483648 bytes)

print(MAX_UPLOAD_SIZE)           # Output: 10485760
print(type(MAX_UPLOAD_SIZE))     # Output: <class 'int'>

Time Helper Functions

from sizelib import time

TIMEOUT = time.s(30)        # 30 s
CACHE_TTL = time.m(15)      # 900 s
TOKEN_EXPIRY = time.h(2)    # 7200 s
WORKER_WAIT = time.ms(500)  # 0.5 s

Humanize Byte Sizes (human_size)

from sizelib import human_size, size

# Default binary formatting (base 2 / 1024)
print(human_size(MAX_UPLOAD_SIZE))  # Output: 10 MiB
print(human_size(CACHE_LIMIT))      # Output: 2 GiB

# Decimal values are formatted up to 2 decimal places
TOTAL = CACHE_LIMIT + size.mib(500)
print(human_size(TOTAL))            # Output: 2.49 GiB

# Decimal formatting (base 10 / 1000)
print(human_size(USER_QUOTA, base=10))  # Output: 50 GB

Humanize Times (human_time)

from sizelib import human_time, time

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
print(human_time(time.h(2)))    # Output: 2 h
print(human_time(time.d(1)))    # Output: 1 d

Features

FEATURE DESCRIPTION
📏 Size Helpers Standardized functions for all major divisions (kb, mb, gb, tb, kib, mib, gib, tib)
Time Helpers Clean scaling for duration units (ms, s, m, h, d, w)
🧪 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

🏗️ System Architecture

# COMPONENT DESCRIPTION STACK
1️⃣ Sizelib Size & Time The math factor constants and unit calculation helper functions Python
2️⃣ Sizelib Humanize The humanization formatting modules for size and time units Python

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

sizelib-0.2.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sizelib-0.2.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file sizelib-0.2.1.tar.gz.

File metadata

  • Download URL: sizelib-0.2.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for sizelib-0.2.1.tar.gz
Algorithm Hash digest
SHA256 4abf5ef56302af9d5a96e27c2d2df16974994b05f6296a077d6abb36abbef8e2
MD5 9344a0a6d09d9c4a037d468826bd11bd
BLAKE2b-256 6e1e84f351110585769b5e90e3db5197f55731b8843a148aa8962cf15fd89f90

See more details on using hashes here.

File details

Details for the file sizelib-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: sizelib-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for sizelib-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 38cd72fa46b7ade796c33c7eabb6b401b1cc91490000d0e0499973007162d3f7
MD5 a094387be420824345b94cd1e2a4d5e9
BLAKE2b-256 6cfdc15e999f22b89abbe967b72ae3d62cbeb19600a64df99e445a29f980fa39

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.3

2 files

0.2.2

2 files

This release

0.2.1 This release

2 files

0.2.0

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page