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.4.tar.gz (4.0 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.4-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: philiprehberger_filesize-0.1.4.tar.gz
  • Upload date:
  • Size: 4.0 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.4.tar.gz
Algorithm Hash digest
SHA256 142fccee842cc667ce36752d040b2387df0a721654360e440868af79643ea253
MD5 f97a635ae3538a30220ea3ab3980137a
BLAKE2b-256 a198d17250da27841344bfbaeac89a38be47d4bea4d6a3abdab01f2d06e77d49

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_filesize-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b9af445787aacc287607fc2ee0072c982a3c3a806c2bbac4faa7277fa82e4f70
MD5 aacf3ae593a24c76d8e6c211a646a527
BLAKE2b-256 942421207f2cb4cce8cdcd09f05aaa09bc1beec9c358a9d82ef51a0b26c13296

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