humanfriendly
raw JSON → 10.0 verified Tue May 12 auth: no python install: verified quickstart: stale
humanfriendly is a Python library that provides user-friendly output for text interfaces, including parsing and formatting numbers, file sizes, pathnames, and timespans. It also offers utilities for terminal interaction like text styling and prompting. The current version is 10.0, released in September 2021, with a release cadence that has included several minor and major updates in recent years and ongoing maintenance for Python compatibility on various platforms.
pip install humanfriendly Common errors
error ModuleNotFoundError: No module named 'humanfriendly' ↓
cause The 'humanfriendly' package is not installed in the Python environment, or the environment where it's installed is not active.
fix
Install the package using pip:
pip install humanfriendly error ImportError: cannot import name 'on_windows' from 'humanfriendly.compat' ↓
cause This error often occurs when an Anaconda distribution of `humanfriendly` is used, which might be an older or differently compiled version missing the `on_windows` function in `humanfriendly.compat`.
fix
Remove the current
humanfriendly installation and reinstall it from the conda-forge channel: conda remove humanfriendly then conda install -c conda-forge humanfriendly. error ModuleNotFoundError: No module named 'readline' ↓
cause When using interactive functions like `humanfriendly.prompts.prompt_for_confirmation()` on Windows, the underlying `readline` module (which is primarily for Unix-like systems) is required but not available.
fix
On Windows,
humanfriendly often falls back to a simpler input mechanism if readline is not found, but if a specific setup tries to enforce it or if the fallback fails, you might need to ensure colorama is installed for better terminal compatibility: pip install colorama. For prompt_for_confirmation specifically, consider if an alternative input method or a platform-specific check is needed if readline is strictly required. error humanfriendly.exceptions.InvalidSize: Invalid size: 'invalid string' ↓
cause The `humanfriendly.parse_size()` function received an input string that it could not interpret as a valid file size (e.g., 'invalid string', '5 Z').
fix
Ensure the input string to
parse_size() is in a recognized human-friendly format, such as '10 KB', '1.5 GB', '500 bytes', or simply '1024'. Example: parse_size('1.5 GB') error ModuleNotFoundError: No module named 'humanfriendly.tables' ↓
cause This error indicates an attempt to import a function, such as `format_pretty_table`, from `humanfriendly.tables`, but the `tables` submodule is not found or correctly exposed in the package structure.
fix
The correct way to import
format_pretty_table is usually from humanfriendly.tables import format_pretty_table. If this still fails, ensure your humanfriendly installation is complete and not corrupted, and that you are using a version where format_pretty_table is indeed part of humanfriendly.tables. If format_pretty_table was moved or renamed in a newer version, consult the changelog for the correct import path. (For version 10.0, this import is generally valid.) Warnings
deprecated Many functions previously available directly from the top-level `humanfriendly` package are now aliases to functions in submodules (e.g., `humanfriendly.prompts.prompt_for_input`). Accessing these aliases will trigger a `DeprecationWarning`. ↓
fix Import functions directly from their respective submodules (e.g., `from humanfriendly.prompts import prompt_for_input`). Refer to the API documentation for correct paths.
breaking The internal `time_units` data structure was changed. Although not formally part of the documented API, this constitutes a technically backwards incompatible change if users were directly importing or relying on this internal variable. ↓
fix Avoid direct reliance on internal data structures. Use documented functions for time-related operations (e.g., `format_timespan`, `parse_timespan`).
gotcha The default behavior for `format_size()` and `parse_size()` changed from using binary multiples (base-2, e.g., KiB) to decimal multiples (base-10, e.g., KB) in an earlier major version. Users expecting binary representation by default may get unexpected results. ↓
fix Explicitly pass `binary=True` to `format_size()` and `parse_size()` if you require binary (base-2) multiples. For example: `format_size(num_bytes, binary=True)`.
gotcha On Windows, advanced terminal styling and ANSI escape sequence features (like colors and spinners) might not work correctly without the `colorama` package, especially on older Windows versions. While Windows 10+ has native support, `colorama` provides broader compatibility. ↓
fix Install `colorama` as an optional dependency: `pip install colorama`. `humanfriendly` will detect and use it automatically.
gotcha The `prompt_for_input()` function, and other interactive prompt functions, will raise an `EOFError` if run in a non-interactive environment where standard input (stdin) is closed or redirected to an empty source. These functions expect user input from a terminal. ↓
fix Ensure the script is run in an interactive terminal. If the script must run non-interactively, avoid calling interactive prompt functions or provide input via redirection (e.g., `echo 'my input' | python script.py`).
breaking `humanfriendly.prompts.prompt_for_input()` and other interactive prompt functions expect an interactive terminal. Running these functions in a non-interactive environment (e.g., CI/CD pipeline, redirected input, or when a TTY is not allocated) will result in an `EOFError` because no input can be read from `stdin`. ↓
fix Ensure the script is executed in an interactive terminal. If running in a non-interactive environment, avoid using interactive prompt functions or handle `EOFError` gracefully. For automated scripts, provide input via environment variables, command-line arguments, or configuration files instead of interactive prompts.
Install compatibility verified last tested: 2026-05-12
python os / libc status wheel install import disk
3.10 alpine (musl) - - 0.13s 18.4M
3.10 slim (glibc) - - 0.13s 19M
3.11 alpine (musl) - - 0.16s 20.3M
3.11 slim (glibc) - - 0.09s 21M
3.12 alpine (musl) - - 0.10s 12.1M
3.12 slim (glibc) - - 0.14s 13M
3.13 alpine (musl) - - 0.13s 11.8M
3.13 slim (glibc) - - 0.12s 12M
3.9 alpine (musl) - - 0.08s 17.9M
3.9 slim (glibc) - - 0.07s 18M
Imports
- format_size wrong
import humanfriendly; humanfriendly.format_size(...)correctfrom humanfriendly import format_size - parse_size wrong
import humanfriendly; humanfriendly.parse_size(...)correctfrom humanfriendly import parse_size - prompt_for_input wrong
from humanfriendly import prompt_for_inputcorrectfrom humanfriendly.prompts import prompt_for_input - format_timespan
from humanfriendly import format_timespan
Quickstart stale last tested: 2026-04-23
import os
from humanfriendly import format_size, parse_size
from humanfriendly.prompts import prompt_for_input
# Example of parsing and formatting file sizes
user_input = prompt_for_input("Enter a human-readable file size (e.g., 16GB, 5MB): ")
num_bytes = parse_size(user_input)
print(f"Parsed bytes: {num_bytes}")
print(f"Formatted (decimal): {format_size(num_bytes)}")
print(f"Formatted (binary): {format_size(num_bytes, binary=True)}")
# Example of formatting a timespan
from humanfriendly import format_timespan
seconds = 3665 # 1 hour, 1 minute, 5 seconds
print(f"Formatted timespan: {format_timespan(seconds)}")
# To demonstrate CLI features like spinners (requires running in terminal):
# import subprocess
# subprocess.run(['humanfriendly', '--demo'])