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.
🚀 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
datetimeand pure calendardateobjects. - Tech-Friendly: Formats strings cleanly (
15m agoinstead offifteen 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"
Project details
Release history Release notifications | RSS feed
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d447d8be159622eb2b8d19663a9d9dc7c0f2fbcd0c503e63ddbc2d3126d788fe
|
|
| MD5 |
19a714652e0035122089aaa8eda6fc09
|
|
| BLAKE2b-256 |
5abf24583d03d3d3f2ce5c8d81d86f55a734f36d55f1e5ee14db9f9b7eebb73b
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4208f2c6087e0818adb0345ec26c4e83a830b19ab253b896f4710e7bdb26553e
|
|
| MD5 |
d4e4fa801a027a63dc5d8f67fd74896a
|
|
| BLAKE2b-256 |
d46219f59058c53a35620298e72b1d9b29a017eb7f8e8b83c252575566a7679e
|