Skip to main content

Convert between seconds and human-readable time in CLI or code.

Project description

py-humantime

PyPI version Build Status License: MIT

A production-ready Python package and CLI tool to convert between seconds and human-readable time strings.

Features

  • Convert seconds to human-readable time (e.g., 1h 2m 3s)
  • Convert human-readable time to seconds (e.g., 1h 2m 3s3723)
  • Simple, extensible, and dependency-free
  • Usable as both a CLI tool and Python module
  • Helpful error messages and input validation
  • Fully tested and ready for PyPI/GitHub

Installation

pip install py-humantime

Development install

pip install .

CLI Usage

Convert seconds to human-readable:

py-humantime --to-human 4523        # → 1h 15m 23s

Convert human-readable to seconds:

py-humantime --to-seconds "1h 15m"  # → 4500

Python Usage

from pyhumantime import seconds_to_human, human_to_seconds

print(seconds_to_human(4523))          # → '1h 15m 23s'
print(human_to_seconds("1h 15m 23s"))  # → 4523

Error Handling Example

from pyhumantime import human_to_seconds

try:
    print(human_to_seconds('notatime'))
except ValueError as e:
    print('Error:', e)

Extensibility

  • The core logic is OOP-based and can be extended to support new units (e.g., milliseconds, days) by subclassing or enhancing HumanTimeConverter in pyhumantime/core.py.

Contributing

Pull requests and issues are welcome! Please add tests for new features or bug fixes.

License

MIT License

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

py_humantime-0.1.4.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

py_humantime-0.1.4-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file py_humantime-0.1.4.tar.gz.

File metadata

  • Download URL: py_humantime-0.1.4.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.0

File hashes

Hashes for py_humantime-0.1.4.tar.gz
Algorithm Hash digest
SHA256 f516e08a0e6a690b458f656c7813a50333174590f6ddee06fb54d3034c42261c
MD5 eef3cd6cfa342cc9fdc65e8dd8a1a35c
BLAKE2b-256 e6bf0ffe727b0e1d0d275e2e73f069e53d53cf1a58d3ea556a74c2c60d5e1dda

See more details on using hashes here.

File details

Details for the file py_humantime-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: py_humantime-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.0

File hashes

Hashes for py_humantime-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 aacdcdacdf9a35a81d5ebe3f77413870dc69753b5a891a10ec62ce4d61f196bc
MD5 5fb747306beaeecdaa58a1acff3f61ef
BLAKE2b-256 d16567a66414c776d1f71f17209eeae76fc814224df7a6c60e461599ca8763ff

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