Skip to main content

Convert bytes to human-readable file sizes and back

Project description

philiprehberger-filesize

Tests PyPI version License

Convert bytes to human-readable file sizes and back.

Installation

pip install philiprehberger-filesize

Usage

from philiprehberger_filesize import humanize, parse, is_larger_than

humanize(1536)                  # "1.5 KB"
humanize(1073741824)            # "1.0 GB"
humanize(1024, binary=True)     # "1.0 KiB"

parse("1.5 GB")                 # 1500000000
parse("1 KiB")                  # 1024

is_larger_than(5000000, "1 MB") # True

API

  • humanize(size, binary=False, precision=1) — Bytes to human string
  • format_bytes(size, binary=False, precision=2) — Alias with precision=2
  • parse(text) — Human string to bytes
  • is_larger_than(size, threshold) — Compare size to human string

Development

pip install -e .
python -m pytest tests/ -v

License

MIT

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

philiprehberger_filesize-0.1.5.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

philiprehberger_filesize-0.1.5-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_filesize-0.1.5.tar.gz.

File metadata

  • Download URL: philiprehberger_filesize-0.1.5.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for philiprehberger_filesize-0.1.5.tar.gz
Algorithm Hash digest
SHA256 0d33e16c533a3163957d88c1d030f21b2578dab967a61ba65072e3028890dc79
MD5 4b5b79385809484353cfc0e7677e65ac
BLAKE2b-256 b4a851d8c3df6038b1091b75477188a8501e852c10accca05c4918a1531c8db9

See more details on using hashes here.

File details

Details for the file philiprehberger_filesize-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_filesize-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 807448271d7135918946cdf4d76424865d6b1e600cb21af088ada13c5462289a
MD5 0c1aab5455c4f5df6a22bbc4b709a7c1
BLAKE2b-256 c533d25350967f347279bb60901b2f7368b3f5e8d64b13601f7b90e85c2f8d64

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