Skip to main content

A micro-library to instantly convert raw machine data into clean, human-readable strings.

Project description

⏱️ timesaver

A lightning-fast, zero-dependency micro-library to instantly convert messy machine data (raw bytes, seconds, and dates) into sleek, human-readable strings.

PyPI Version License: MIT


🚀 Why timesaver?

Most "humanizing" packages suffer from feature creep—carrying heavy translation files, scientific formulas, and massive footprints. timesaver is built for developers who just want sleek, dashboard-ready strings with zero bloat.

  • Ultra-lightweight: Zero external dependencies. Perfect for AWS Lambda or microservices.
  • Smart Types: Automatically handles both Python datetime and pure calendar date objects.
  • Tech-Friendly: Formats strings cleanly (15m ago instead of fifteen minutes ago) to fit beautiful UI layouts.

📦 Installation

Install it instantly via pip:

pip install timesaver

💻 Quick Start & Examples

Humanizing File Sizes (filesize)

Convert large integers of bytes into dynamically scaled, clean string readouts.

import timesaver

print(timesaver.filesize(1024))       # Output: "1.0 KB"
print(timesaver.filesize(5432100))    # Output: "5.2 MB"
print(timesaver.filesize(1200000000)) # Output: "1.1 GB"

Smart Relative Time (ago)

Pass either a high-precision datetime object or a standard calendar date object. The engine will automatically calculate the difference relative to right now.

import timesaver
import datetime as dt

# Example A: Using a precise datetime (e.g., 15 minutes ago)
past_datetime = dt.datetime.now() - dt.timedelta(minutes=15)
print(timesaver.ago(past_datetime))  # Output: "15m ago"

# Example B: Using a pure calendar date (e.g., 5 days ago)
past_date = dt.date.today() - dt.timedelta(days=5)
print(timesaver.ago(past_date))      # Output: "5d ago"

🛠️ API Reference

timesaver.filesize(bytes_count: int) -> str
Takes an integer representing bytes. Scaled automatically across B, KB, MB, GB, TB, and PB. Raises a ValueError if the number is negative.
timesaver.ago(timestamp: Union[datetime, date]) -> str
Calculates distance from the current time. Breaks down into thresholds:
< 60 seconds -> "just now"

< 1 hour -> "Xm ago"

< 24 hours -> "Xh ago"

< 30 days -> "Xd ago"

< 12 months -> "Xmo ago"

> 1 year -> "Xy ago"

  • Built by Roy Peters LinkedIn

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

timesaver-0.1.0.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

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

timesaver-0.1.0-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file timesaver-0.1.0.tar.gz.

File metadata

  • Download URL: timesaver-0.1.0.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for timesaver-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d447d8be159622eb2b8d19663a9d9dc7c0f2fbcd0c503e63ddbc2d3126d788fe
MD5 19a714652e0035122089aaa8eda6fc09
BLAKE2b-256 5abf24583d03d3d3f2ce5c8d81d86f55a734f36d55f1e5ee14db9f9b7eebb73b

See more details on using hashes here.

File details

Details for the file timesaver-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: timesaver-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for timesaver-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4208f2c6087e0818adb0345ec26c4e83a830b19ab253b896f4710e7bdb26553e
MD5 d4e4fa801a027a63dc5d8f67fd74896a
BLAKE2b-256 d46219f59058c53a35620298e72b1d9b29a017eb7f8e8b83c252575566a7679e

See more details on using hashes here.

Supported by

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