{"id":512,"library":"humanize","title":"Python Humanize Utilities","description":"humanize is a Python library (current version 4.15.0) that provides a collection of utilities to make data more human-readable. It transforms raw numerical values, dates, times, and file sizes into intuitive and easily understandable formats, bridging the gap between machine-centric data and human comprehension. The project maintains an active release cadence, with frequent updates and a focus on expanding localization support.","status":"active","version":"4.15.0","language":"python","source_language":"en","source_url":"https://github.com/python-humanize/humanize","tags":["human-readable","formatting","numbers","dates","times","filesizes","localization"],"install":[{"cmd":"pip install humanize","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"humanize","correct":"import humanize"},{"note":"For direct access to specific formatting functions.","symbol":"intcomma","correct":"from humanize import intcomma"},{"note":"For direct access to specific formatting functions.","symbol":"naturalsize","correct":"from humanize import naturalsize"}],"quickstart":{"code":"import humanize\nimport datetime as dt\n\n# Humanize numbers\nprint(f\"Commas: {humanize.intcomma(1234567)}\")\nprint(f\"Words: {humanize.intword(1234567890)}\")\nprint(f\"Ordinal: {humanize.ordinal(21)}\")\n\n# Humanize dates and times\nnow = dt.datetime.now()\none_hour_ago = now - dt.timedelta(hours=1, minutes=5)\ntomorrow = now + dt.timedelta(days=1)\nprint(f\"Time ago: {humanize.naturaltime(one_hour_ago)}\")\nprint(f\"Time from now: {humanize.naturaltime(tomorrow, future=True)}\")\nprint(f\"Natural day: {humanize.naturalday(now)}\")\n\n# Humanize file sizes\nprint(f\"File size: {humanize.naturalsize(1024 * 1024 * 1.5)}\")\n","lang":"python","description":"This quickstart demonstrates common `humanize` functionalities, including formatting numbers with commas or words, converting numbers to ordinals, presenting dates and times in natural language, and converting byte counts into human-readable file sizes."},"warnings":[{"fix":"Upgrade Python to 3.10 or newer, or pin `humanize < 4.14.0` in your dependencies.","message":"Python 3.9 support was dropped in humanize version 4.14.0. Users running Python 3.9 or older environments must either upgrade their Python version or pin humanize to a version less than 4.14.0.","severity":"breaking","affected_versions":">=4.14.0"},{"fix":"Upgrade Python to 3.10 or newer, or pin `humanize < 4.11.0` in your dependencies.","message":"Python 3.8 support was dropped in humanize version 4.11.0. Users running Python 3.8 or older environments must either upgrade their Python version or pin humanize to a version less than 4.11.0.","severity":"breaking","affected_versions":">=4.11.0"},{"fix":"Upgrade to humanize 4.13.0 or a newer version to benefit from improved rounding and precision in `naturaldelta`.","message":"`naturaldelta` in versions prior to 4.13.0 had rounding issues that could lead to less precise human-readable duration strings.","severity":"gotcha","affected_versions":"<4.13.0"},{"fix":"Upgrade to humanize 4.12.3 or a newer version to resolve the `naturalsize` float input regression.","message":"Versions 4.12.0 and 4.12.1 introduced regressions where `naturalsize` could incorrectly format float inputs.","severity":"gotcha","affected_versions":"4.12.0 - 4.12.2"}],"env_vars":null,"last_verified":"2026-05-12T14:31:32.699Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Install the package using pip: `pip install humanize`","cause":"The 'humanize' package has not been installed in your Python environment, or the Python interpreter you are using does not have access to the installed package.","error":"ModuleNotFoundError: No module named 'humanize'"},{"fix":"Ensure both datetime objects are either consistently timezone-naive or timezone-aware and in the same timezone. You can explicitly provide a timezone-aware reference point using the `when` parameter in `naturaltime`. \n```python\nimport datetime\nimport humanize\n\n# Example: Convert to UTC if the original datetime is timezone-aware\naware_dt = datetime.datetime.now(datetime.timezone.utc)\nprint(humanize.naturaltime(aware_dt, when=datetime.datetime.now(datetime.timezone.utc)))\n\n# Example: Make the input datetime naive if local time comparison is intended\nnaive_dt = datetime.datetime.now().replace(tzinfo=None)\nprint(humanize.naturaltime(naive_dt))\n```","cause":"The `humanize.naturaltime` function is being called with a timezone-aware datetime object, but it's being compared internally with a timezone-naive `datetime.now()`, leading to a type mismatch.","error":"TypeError: can't subtract offset-naive and offset-aware datetimes"},{"fix":"First, ensure the function name is spelled correctly. If it is, upgrade the `humanize` library to its latest version: `pip install --upgrade humanize`. Then consult the official documentation for the correct usage.","cause":"You are attempting to use a function (like `precisedelta`) that either does not exist in the version of `humanize` currently installed, was deprecated, or the function name is misspelled. `precisedelta` was introduced in a later version, so an older installed version might not have it.","error":"AttributeError: module 'humanize' has no attribute 'precisedelta'"},{"fix":"Ensure the locale string is correct (e.g., 'es_ES', 'fr_FR') and that the necessary translation files for `humanize` exist and are accessible at the specified path (if provided). If using a standard locale, ensure `humanize` is correctly installed, as it ships with its own translations. \n```python\nimport humanize\n\n# Example with a supported locale\ntry:\n    humanize.i18n.activate('es_ES')\n    print(humanize.naturalday(datetime.date.today()))\nexcept FileNotFoundError as e:\n    print(f\"Translation error: {e}. Check if 'es_ES' translations are available or path is correct.\")\n```","cause":"This error occurs when `humanize.i18n.activate()` is called with a locale that does not have corresponding translation files, or the specified `path` to translation files is incorrect or inaccessible.","error":"FileNotFoundError: [Errno 2] No translation file found for domain: 'humanize'"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.4,"disk_size":"18.6M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.4,"disk_size":"19M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.4,"disk_size":"20.4M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.6,"disk_size":"21M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.4,"disk_size":"12.3M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.4,"disk_size":"13M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.7,"disk_size":"11.9M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.5,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.3,"disk_size":"18.1M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.3,"disk_size":"19M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}