{"id":13713426,"url":"https://github.com/python-humanize/humanize","last_synced_at":"2025-10-20T16:04:52.879Z","repository":{"id":36985539,"uuid":"466683324","full_name":"python-humanize/humanize","owner":"python-humanize","description":"Python humanize functions","archived":false,"fork":false,"pushed_at":"2025-05-01T12:58:24.000Z","size":869,"stargazers_count":597,"open_issues_count":25,"forks_count":69,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-05-01T13:50:24.236Z","etag":null,"topics":["date","hacktoberfest","humanise","humanize","python","time"],"latest_commit_sha":null,"homepage":"https://humanize.readthedocs.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/python-humanize.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"hugovk","tidelift":"pypi/humanize"}},"created_at":"2022-03-06T08:50:33.000Z","updated_at":"2025-05-01T12:58:26.000Z","dependencies_parsed_at":"2023-12-09T16:27:20.115Z","dependency_job_id":"6f331422-7336-4ca5-abfa-02fa20ae3473","html_url":"https://github.com/python-humanize/humanize","commit_stats":null,"previous_names":[],"tags_count":54,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-humanize%2Fhumanize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-humanize%2Fhumanize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-humanize%2Fhumanize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-humanize%2Fhumanize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/python-humanize","download_url":"https://codeload.github.com/python-humanize/humanize/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252787531,"owners_count":21804277,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["date","hacktoberfest","humanise","humanize","python","time"],"created_at":"2024-08-02T23:01:35.963Z","updated_at":"2025-10-20T16:04:52.873Z","avatar_url":"https://github.com/python-humanize.png","language":"Python","readme":"# humanize\n\n[![PyPI version](https://img.shields.io/pypi/v/humanize.svg?logo=pypi\u0026logoColor=FFE873)](https://pypi.org/project/humanize/)\n[![Supported Python versions](https://img.shields.io/pypi/pyversions/humanize.svg?logo=python\u0026logoColor=FFE873)](https://pypi.org/project/humanize/)\n[![Documentation Status](https://readthedocs.org/projects/python-humanize/badge/?version=latest)](https://humanize.readthedocs.io/en/latest/?badge=latest)\n[![PyPI downloads](https://img.shields.io/pypi/dm/humanize.svg)](https://pypistats.org/packages/humanize)\n[![GitHub Actions status](https://github.com/python-humanize/humanize/workflows/Test/badge.svg)](https://github.com/python-humanize/humanize/actions)\n[![codecov](https://codecov.io/gh/python-humanize/humanize/branch/main/graph/badge.svg)](https://codecov.io/gh/python-humanize/humanize)\n[![MIT License](https://img.shields.io/github/license/python-humanize/humanize.svg)](LICENCE)\n[![Tidelift](https://tidelift.com/badges/package/pypi/humanize)](https://tidelift.com/subscription/pkg/pypi-humanize?utm_source=pypi-humanize\u0026utm_medium=badge)\n\nThis modest package contains various common humanization utilities, like turning a\nnumber into a fuzzy human-readable duration (\"3 minutes ago\") or into a human-readable\nsize or throughput. It is localized to:\n\n- Arabic\n- Basque\n- Bengali\n- Brazilian Portuguese\n- Catalan\n- Danish\n- Dutch\n- Esperanto\n- European Portuguese\n- Finnish\n- French\n- German\n- Greek\n- Hebrew\n- Indonesian\n- Italian\n- Japanese\n- Klingon\n- Korean\n- Norwegian\n- Persian\n- Polish\n- Russian\n- Simplified Chinese\n- Slovak\n- Slovenian\n- Spanish\n- Swedish\n- Turkish\n- Ukrainian\n- Uzbek\n- Vietnamese\n\n## API reference\n\n[https://humanize.readthedocs.io](https://humanize.readthedocs.io/)\n\n\u003c!-- usage-start --\u003e\n\n## Installation\n\n### From PyPI\n\n```bash\npython3 -m pip install --upgrade humanize\n```\n\n### From source\n\n```bash\ngit clone https://github.com/python-humanize/humanize\ncd humanize\npython3 -m pip install -e .\n```\n\n## Usage\n\n### Integer humanization\n\n```pycon\n\u003e\u003e\u003e import humanize\n\u003e\u003e\u003e humanize.intcomma(12345)\n'12,345'\n\u003e\u003e\u003e humanize.intword(123455913)\n'123.5 million'\n\u003e\u003e\u003e humanize.intword(12345591313)\n'12.3 billion'\n\u003e\u003e\u003e humanize.apnumber(4)\n'four'\n\u003e\u003e\u003e humanize.apnumber(41)\n'41'\n```\n\n### Date \u0026 time humanization\n\n```pycon\n\u003e\u003e\u003e import humanize\n\u003e\u003e\u003e import datetime as dt\n\u003e\u003e\u003e humanize.naturalday(dt.datetime.now())\n'today'\n\u003e\u003e\u003e humanize.naturaldelta(dt.timedelta(seconds=1001))\n'16 minutes'\n\u003e\u003e\u003e humanize.naturalday(dt.datetime.now() - dt.timedelta(days=1))\n'yesterday'\n\u003e\u003e\u003e humanize.naturalday(dt.date(2007, 6, 5))\n'Jun 05'\n\u003e\u003e\u003e humanize.naturaldate(dt.date(2007, 6, 5))\n'Jun 05 2007'\n\u003e\u003e\u003e humanize.naturaltime(dt.datetime.now() - dt.timedelta(seconds=1))\n'a second ago'\n\u003e\u003e\u003e humanize.naturaltime(dt.datetime.now() - dt.timedelta(seconds=3600))\n'an hour ago'\n```\n\n### Precise time delta\n\n```pycon\n\u003e\u003e\u003e import humanize\n\u003e\u003e\u003e import datetime as dt\n\u003e\u003e\u003e delta = dt.timedelta(seconds=3633, days=2, microseconds=123000)\n\u003e\u003e\u003e humanize.precisedelta(delta)\n'2 days, 1 hour and 33.12 seconds'\n\u003e\u003e\u003e humanize.precisedelta(delta, minimum_unit=\"microseconds\")\n'2 days, 1 hour, 33 seconds and 123 milliseconds'\n\u003e\u003e\u003e humanize.precisedelta(delta, suppress=[\"days\"], format=\"%0.4f\")\n'49 hours and 33.1230 seconds'\n```\n\n#### Smaller units\n\nIf seconds are too large, set `minimum_unit` to milliseconds or microseconds:\n\n```pycon\n\u003e\u003e\u003e import humanize\n\u003e\u003e\u003e import datetime as dt\n\u003e\u003e\u003e humanize.naturaldelta(dt.timedelta(seconds=2))\n'2 seconds'\n```\n\n```pycon\n\u003e\u003e\u003e delta = dt.timedelta(milliseconds=4)\n\u003e\u003e\u003e humanize.naturaldelta(delta)\n'a moment'\n\u003e\u003e\u003e humanize.naturaldelta(delta, minimum_unit=\"milliseconds\")\n'4 milliseconds'\n\u003e\u003e\u003e humanize.naturaldelta(delta, minimum_unit=\"microseconds\")\n'4 milliseconds'\n```\n\n```pycon\n\u003e\u003e\u003e humanize.naturaltime(delta)\n'now'\n\u003e\u003e\u003e humanize.naturaltime(delta, minimum_unit=\"milliseconds\")\n'4 milliseconds ago'\n\u003e\u003e\u003e humanize.naturaltime(delta, minimum_unit=\"microseconds\")\n'4 milliseconds ago'\n```\n\n### File size humanization\n\n```pycon\n\u003e\u003e\u003e import humanize\n\u003e\u003e\u003e humanize.naturalsize(1_000_000)\n'1.0 MB'\n\u003e\u003e\u003e humanize.naturalsize(1_000_000, binary=True)\n'976.6 KiB'\n\u003e\u003e\u003e humanize.naturalsize(1_000_000, gnu=True)\n'976.6K'\n```\n\n### Human-readable floating point numbers\n\n```pycon\n\u003e\u003e\u003e import humanize\n\u003e\u003e\u003e humanize.fractional(1/3)\n'1/3'\n\u003e\u003e\u003e humanize.fractional(1.5)\n'1 1/2'\n\u003e\u003e\u003e humanize.fractional(0.3)\n'3/10'\n\u003e\u003e\u003e humanize.fractional(0.333)\n'333/1000'\n\u003e\u003e\u003e humanize.fractional(1)\n'1'\n```\n\n### Scientific notation\n\n```pycon\n\u003e\u003e\u003e import humanize\n\u003e\u003e\u003e humanize.scientific(0.3)\n'3.00 x 10⁻¹'\n\u003e\u003e\u003e humanize.scientific(500)\n'5.00 x 10²'\n\u003e\u003e\u003e humanize.scientific(\"20000\")\n'2.00 x 10⁴'\n\u003e\u003e\u003e humanize.scientific(1**10)\n'1.00 x 10⁰'\n\u003e\u003e\u003e humanize.scientific(1**10, precision=1)\n'1.0 x 10⁰'\n\u003e\u003e\u003e humanize.scientific(1**10, precision=0)\n'1 x 10⁰'\n```\n\n## Localization\n\nHow to change locale at runtime:\n\n```pycon\n\u003e\u003e\u003e import humanize\n\u003e\u003e\u003e import datetime as dt\n\u003e\u003e\u003e humanize.naturaltime(dt.timedelta(seconds=3))\n'3 seconds ago'\n\u003e\u003e\u003e _t = humanize.i18n.activate(\"ru_RU\")\n\u003e\u003e\u003e humanize.naturaltime(dt.timedelta(seconds=3))\n'3 секунды назад'\n\u003e\u003e\u003e humanize.i18n.deactivate()\n\u003e\u003e\u003e humanize.naturaltime(dt.timedelta(seconds=3))\n'3 seconds ago'\n```\n\nYou can pass additional parameter `path` to `activate` to specify a path to search\nlocales in.\n\n```pycon\n\u003e\u003e\u003e import humanize\n\u003e\u003e\u003e humanize.i18n.activate(\"xx_XX\")\n\u003c...\u003e\nFileNotFoundError: [Errno 2] No translation file found for domain: 'humanize'\n\u003e\u003e\u003e humanize.i18n.activate(\"pt_BR\", path=\"path/to/my/own/translation/\")\n\u003cgettext.GNUTranslations instance ...\u003e\n```\n\n\u003c!-- usage-end --\u003e\n\nHow to add new phrases to existing locale files:\n\n```sh\nxgettext --from-code=UTF-8 -o humanize.pot -k'_' -k'N_' -k'P_:1c,2' -k'NS_:1,2' -k'_ngettext:1,2' -l python src/humanize/*.py  # extract new phrases\nmsgmerge -U src/humanize/locale/ru_RU/LC_MESSAGES/humanize.po humanize.pot # add them to locale files\n```\n\nHow to add a new locale:\n\n```sh\nmsginit -i humanize.pot -o humanize/locale/\u003clocale name\u003e/LC_MESSAGES/humanize.po --locale \u003clocale name\u003e\n```\n\nWhere `\u003clocale name\u003e` is a locale abbreviation, eg. `en_GB`, `pt_BR` or just `ru`, `fr`\netc.\n\nList the language at the top of this README.\n","funding_links":["https://github.com/sponsors/hugovk","https://tidelift.com/funding/github/pypi/humanize","https://tidelift.com/badges/package/pypi/humanize","https://tidelift.com/subscription/pkg/pypi-humanize?utm_source=pypi-humanize\u0026utm_medium=badge"],"categories":["Data Format \u0026 I/O","Python"],"sub_categories":["For Python"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpython-humanize%2Fhumanize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpython-humanize%2Fhumanize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpython-humanize%2Fhumanize/lists"}