Skip to main content

Parses & Formats integer file sizes to human readable file sizes.

Example Usage

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

Formatting

>>> '{: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'

Documentation

Parsing Options

  • case_sensitive: Use 1024 for upper case and 1000 for lower case if casing exists, as is common in unix utilities, e.g. dd

  • default_binary: Default base if it is not clear what the unit is (i.e. if it is not ‘mib’ or ‘mebibytes’)

Formatting Options

  • format type: [hH][size_format][^exponent]

    • h: Base 1000

    • H: Base 1024

  • size_format: c | cs | cv | e | ev | s | sv

    • c: Commonly used case-sensitive suffixes

    • cs: Commonly used abbreviated case-sensitive suffixes

    • cv: Commonly used verbose case-sensitive suffixes

    • e: IEC suffixes

    • ev: IEC verbose suffixes

    • s: SI suffixes

    • sv: SI verbose suffixes

  • exponent: integer

References

Inspired by:

License

Licensed under GPLv3.

Metadata

Release files for hfilesize 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hfilesize 0.1.0
File Size Uploaded Provenance Actions
hfilesize-0.1.0.zip 7.4 kB Without provenance Details for hfilesize-0.1.0.zip

Release files / hfilesize-0.1.0.zip

Download URL hfilesize-0.1.0.zip
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
560578c395a3b9b0fd25f93c6fb75008e0797cff48b462656c2bc7373179fa30
BLAKE2b-256 checksum
How to use checksums
6f2923423e1022626fe2251fbbf3e0854c6f1e954d740537718938ba5072c8a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for hfilesize 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page