Skip to main content

⏱️ 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

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.2.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.2-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for timesaver-0.1.2.tar.gz
Algorithm Hash digest
SHA256 744155e7142c07dd8e3c6c802ee4d72e2ab8615a4a0b201a3c5f1bfb04e4ffc4
MD5 dab701e8de2a980055c45be62e239ce7
BLAKE2b-256 1573184db2ad372ec349c4cb3069f396143ae861debe1da9e67389c38a79e3ca

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for timesaver-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ba1caa97609a8609bad9dc63adb7318f6f17965f4fb2e0b826717b54a90bdc41
MD5 42c878fa6a00e6927e7595b572d26daa
BLAKE2b-256 781f372ccce3f03652bf47d8ddbedcbe7f2f22293aa0ba9a09095ceececb80b6

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.2 This release

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