Skip to main content

python humanize utilities

Project description

humanize

This modest package contains various common humanization utilities, like turning a number into a fuzzy human readable duration (‘3 minutes ago’) or into a human readable size or throughput.

usage

Integer humanization:

>>> import humanize
>>> humanize.intcomma(12345)
'12,345'
>>> humanize.intword(123455913)
'123.5 million'
>>> humanize.intword(12345591313)
'12.3 billion'
>>> humanize.apnumber(4)
'four'
>>> humanize.apnumber(41)
'41'

Date & time humanization:

>>> import datetime
>>> humanize.naturalday(datetime.datetime.now())
'today'
>>> humanize.naturalday(datetime.datetime.now() - datetime.timedelta(days=1))
'yesterday'
>>> humanize.naturaltime(datetime.datetime.now() - datetime.timedelta(seconds=1))
'a second ago'
>>> humanize.naturaltime(datetime.datetime.now() - datetime.timedelta(seconds=3600))
'an hour ago'

Filesize humanization:

>>> humanize.naturalsize(1000000)
'1.0 MB'
>>> humanize.naturalsize(1000000, binary=True)
'976.6 KiB'
>>> humanize.naturalsize(1000000, gnu=True)
'976.6K'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

humanize-0.2.tar.gz (5.7 kB view details)

Uploaded Source

File details

Details for the file humanize-0.2.tar.gz.

File metadata

  • Download URL: humanize-0.2.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for humanize-0.2.tar.gz
Algorithm Hash digest
SHA256 fb84a13667c0d756fe6ec0ba5d290a4fd6757a5fb246acde48dc63f955bea289
MD5 89aca8e1423d081c6df9137f116fc2db
BLAKE2b-256 56c304ab9981c86beeed434c47732ade7bfe75b1f908f61f84d9fc9504ef3ca2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page