Skip to main content

Human Seconds

Convert a number of seconds into a human-readable time string.

For example, 3675 seconds becomes:

"1 hour, 1 minute and 15 seconds"

This package is ideal for scripts, applications, or tools where you want to display time in a natural, readable format.


Why?

Working with raw seconds isn’t always user-friendly. Whether you’re logging durations, displaying timers, or showing elapsed time to users, converting seconds into a clear, natural sentence improves readability and user experience.

Human Seconds handles this conversion for you cleanly, correctly, and with proper pluralisation, so you can focus on your application logic instead of formatting time.


Features

  • Convert seconds into hours, minutes, and seconds
  • Output a clean, human-readable string
  • Correct handling of singular and plural units
  • Small, lightweight, and dependency-free

Technologies

  • Python >= 3.9

Installation

Install via pip:

pip install human-seconds

Usage

Basic usage

from human_seconds.converter import SecondsToTime

time = SecondsToTime(3675)
print(time.format_to_human_readable())
# "1 hour, 1 minute and 15 seconds"


time = SecondsToTime(62)
print(time.format_to_human_readable())
# "1 minute and 2 seconds"

Accessing individual components

time = SecondsToTime(3675)

print(time.hours)    # 1
print(time.minutes)  # 1
print(time.seconds)  # the total number of seconds

print(time.hours_minutes_and_seconds)  # (1, 1, 15)
print(time.format_to_human_readable())             # "1 hour, 1 minute and 15 seconds"

Updating the total seconds via seconds

You can update the total number of seconds after initialisation. The value will be normalised automatically into hours, minutes, and seconds.

time         = SecondsToTime(3675)  # original: 1 hour, 1 minute, 15 seconds
time.seconds = 100                  # update total seconds

print(time.hours)    # 0
print(time.minutes)  # 1
print(time.seconds)  # the total number of seconds

print(time.hours_minutes_and_seconds)   # (0, 1, 40)
print(time.format_to_human_readable()) # "1 minute and 40 seconds"

API overview

SecondsToTime(total_seconds: int)

Creates a new time object from a total number of seconds.

  • seconds must be a non-negative integer

Properties

  • hours → number of hours
  • minutes → remaining minutes
  • seconds → remaining seconds
  • hours_minutes_and_seconds(hours, minutes, seconds) tuple

Methods

  • format_to_human_readable() → returns a human-readable time string

Edge cases

SecondsToTime(0).format_to_human_readable()
# ""

SecondsToTime(3600).format_to_human_readable()
# "1 hour"

Negative values are not supported.


Requirements

  • Python 3.9 or higher

Development

Clone the repository:

git clone https://github.com/EgbieAndersonUku1/human_seconds.git .
cd human-seconds

Example usage

from human_seconds.converter import SecondsToTime

time = SecondsToTime(3675)

print(time.hours)   # 1
print(time.minutes) # 1
print(time.seconds) # 15
print(time.format_to_human_readable()) # '1 hour, 1 minute and 15 seconds'


# Use the `seconds` setter to update the remaining seconds;
# the total time will be automatically normalized
time.seconds = 100


print(time.hours)   # 0
print(time.minutes) # 1
print(time.seconds) # 40
print(time.format_to_human_readable()) # '1 minute and 40 seconds'

Licence

MIT Licence

Release files for human-seconds 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for human-seconds 0.1.2
File Size Uploaded
human_seconds-0.1.2.tar.gz 5.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for human-seconds 0.1.2
File Interpreter ABI Platform
human_seconds-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 11.1 kB

Release files / human_seconds-0.1.2.tar.gz

Download URL human_seconds-0.1.2.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
9d706d6db47c19c6ee5a98e94e3f7fc7aaeaea6d813b823aa320f925d2f1e594
BLAKE2b-256 checksum
How to use checksums
4f594b71630bc931668418077499c1a53de8e77c21ed0205391ee93a2e7cad24
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / human_seconds-0.1.2-py3-none-any.whl

Download URL human_seconds-0.1.2-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0bf43272b8c93e8c00f8748b5e426357bbdcc63db6b7a895488b26a7b60a017d
BLAKE2b-256 checksum
How to use checksums
6dafff3871512df02d0afdee2fb293e5d818f00f4594b26e881c758df56d708e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page