Convert between seconds and human-readable time in CLI or code.
Project description
py-humantime
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 3s→3723) - 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
HumanTimeConverterinpyhumantime/core.py.
Contributing
Pull requests and issues are welcome! Please add tests for new features or bug fixes.
License
MIT License
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 py_humantime-0.1.3.tar.gz.
File metadata
- Download URL: py_humantime-0.1.3.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df9155b7945985917a7975e5059eaf1842f1970b2238d55dc7a65593b3e2bc55
|
|
| MD5 |
b8ab630b374c04dd9240817701262e82
|
|
| BLAKE2b-256 |
94dbaf5a7c28501e0cad5df13461c17b2fb2dd191e0edb2a47e7cb5246673a52
|
File details
Details for the file py_humantime-0.1.3-py3-none-any.whl.
File metadata
- Download URL: py_humantime-0.1.3-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e4a3b5a57141cecff143471b9b6916476598fa2fdde0ba83a1cbfade2ef18e0
|
|
| MD5 |
6ef6b30cd808e144eddfd02a8e774a01
|
|
| BLAKE2b-256 |
9f027933045c7cd1074e169ead5b7d33bcdd74cacf8255e8382d696c402bef0b
|