Human Readable
The `human-readable` library provides a collection of utilities to convert various data types, such as numbers, dates, times, file sizes, and lists, into a more human-friendly and readable format. It aims to enhance user experience by presenting machine-generated data in an intuitive way. The current version is 2.0.2 and it is actively maintained, with the latest release on March 26, 2026.
Common errors
-
ModuleNotFoundError: No module named 'humanize'
cause Attempting to import `humanize` when `human-readable` is installed, or vice-versa. These are distinct libraries.fixIf you intended to use `human-readable`, use `import human_readable`. If you intended `humanize`, ensure it's installed via `pip install humanize` and import it correctly. -
AttributeError: module 'human_readable' has no attribute 'some_function'
cause Trying to use a function (e.g., `naturaltime`, `filesize`) that exists in a different humanization library (like `humanize` or `humanreadable`) but not in `human-readable`, or a function that has been renamed or removed in a newer version.fixConsult the `human-readable` documentation (or the specific version's docs) for the correct function names and their usage. For example, `humanize.naturaltime` is `human_readable.time_delta` or `human_readable.date_time` in this library. `humanize.filesize` is `human_readable.file_size`. -
TypeError: 'float' object cannot be interpreted as an integer
cause Passing a float to a function that strictly expects an integer, such as `human_readable.time_of_day`, or an incorrect type to other humanization functions.fixEnsure the input data type matches the function's expected arguments. Convert floats to integers if appropriate, or use functions designed for floats (e.g., `human_readable.scientific`, `human_readable.fractional`) if that's the desired outcome.
Warnings
- breaking Upgrading from `human-readable` 1.x to 2.x may introduce breaking changes. While not explicitly detailed in the public release notes, major version increments (e.g., 1.x to 2.x) typically indicate backward-incompatible API changes following Semantic Versioning principles.
- gotcha There are several Python libraries with similar names or functionalities (e.g., `humanize`, `humanreadable`, `humanfriendly`). Ensure you are importing and using functions from the correct `human_readable` package to avoid unexpected behavior or `AttributeError`s.
- gotcha Localization (i18n) requires explicit activation. If humanization functions return English strings despite your environment being set to another locale, the library's locale might not be activated correctly.
Install
-
pip install human-readable
Imports
- human_readable
import humanreadable
import human_readable
Quickstart
import human_readable import datetime as dt # Date and time humanization print(human_readable.time_of_day(17)) print(human_readable.time_delta(dt.timedelta(seconds=3665))) # File size humanization print(human_readable.file_size(2900000)) # List humanization print(human_readable.listing(['apple', 'banana', 'orange'])) # Numbers humanization print(human_readable.int_comma(123456789)) print(human_readable.int_word(123456789))