Human-readability is always a factor of the design for the output format and hfilesize (GitHub) is a Python package just for a easy method to have a good and easily understandable output.

It does two things, parsing:

>>> from hfilesize import Format, FileSize
>>> FileSize('1k')
... 1000
>>> FileSize('1K')
... 1024
>>> FileSize('1kib')
... 1024
>>> FileSize('1K', default_binary=False, case_sensitive=False)
... 1000
>>> FileSize('1 kibibyte')
... 1024

And formating:

>>> '{:d}'.format(FileSize(1024))
... '1024'
>>> '{:.02fH}'.format(FileSize(1024))
... '1 KB'
>>> '{:.02fHcv}'.format(FileSize(1024))
... '1 kilobyte'
>>> '{:.02fhs}'.format(FileSize(1000))
... '1 KB'
>>> '{:.02fhs^0}'.format(FileSize(1000))
... '1000 B'
>>> '{: >10.02fH}'.format(FileSize(1024))
... '      1 KB'

What I like about this library is it incorporated the format(), that makes it look more Pythonic.

This library actually is inspired by another package called hurry.filesize and they look very alike:

>>> from hurry.filesize import alternative
>>> size(1, system=alternative)
'1 byte'
>>> from hurry.filesize import verbose
>>> size(1024 * 1024 * 3, system=verbose)
'3 megabytes'
>>> from hurry.filesize import si
>>> size(1000, system=si)
'1K'

They both can handle 1000 or 1024 as 1K, but hfilesize has more flexible output in my opinion. Besides, hurry.filesize has not been updated for five years.

hfilesize is written in Python, licensed under the GPLv3.