Ago: Human Readable Timedeltas

0.1.0 · active · verified Thu Apr 16

Ago is a lightweight Python library, currently at version 0.1.0, designed to convert `datetime` and `timedelta` objects into human-readable strings like '3 hours ago' or 'in 5 days'. It focuses on simplicity and customization of tense and precision. The library is actively maintained, with its latest release in March 2025, and maintains a stable, albeit early-stage, release cadence.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the `human` function to convert `datetime` and `timedelta` objects into human-readable strings, including customizing precision and tense. It also shows the usage of `delta2dict` to break down a `timedelta` into its constituent units.

from datetime import datetime, timedelta
from ago import human

# Example with a past datetime object
db_date = datetime(year=2023, month=1, day=1, hour=10, minute=30, second=0)
print(f'Item created: {human(db_date)}')

# Example with a future timedelta object
future_delta = timedelta(days=5, hours=3, minutes=45)
print(f'Task due: {human(future_delta)}')

# Example with custom precision and tense
long_ago = datetime(year=2020, month=3, day=15)
print(f'Event happened: {human(long_ago, precision=3, past_tense="{} since")}')

# Using delta2dict
delta_for_dict = timedelta(days=400, hours=5, minutes=30)
time_components = delta2dict(delta_for_dict)
print(f'Time components: {time_components}')

view raw JSON →