Hurry Filesize
Hurry Filesize is a simple Python library, version 0.9, designed to convert a number of bytes into a human-readable string (e.g., '1K', '2M'). First released in 2009, it provides various systems for formatting, including traditional (1024 multipliers), SI (1000 multipliers), and verbose options. Due to its age, it maintains a very low release cadence, with its current version being its initial public release.
Warnings
- gotcha The default `size` function and its alternative systems provide integer approximations, which may lead to a loss of precision. For example, `size(1031053)` might return '1M' or '2M' rather than '1.03M'.
- deprecated The library has not been updated since its initial release in 2009. While functional for its core purpose, it lacks modern maintenance and may not be actively supported for new Python features or complex edge cases.
- gotcha The `hurry` package itself is a namespace package, which can sometimes lead to confusion regarding its internal structure or sub-package imports if users expect a traditional package with an `__init__.py` at its root.
Install
-
pip install hurry.filesize
Imports
- size
from hurry.filesize import size
- alternative
from hurry.filesize import alternative
- si
from hurry.filesize import si
- verbose
from hurry.filesize import verbose
Quickstart
from hurry.filesize import size, alternative, si, verbose
bytes_value = 1024 * 1024 * 3.5 # 3.5 MB
print(f"Default: {size(bytes_value)}")
print(f"Alternative: {size(bytes_value, system=alternative)}")
print(f"SI: {size(bytes_value, system=si)}")
print(f"Verbose: {size(bytes_value, system=verbose)}")
# Example with smaller values
print(f"10 bytes (default): {size(10)}")
print(f"10 bytes (alternative): {size(10, system=alternative)}")
print(f"10 bytes (verbose): {size(10, system=verbose)}")