bitmath
Pythonic module for representing and manipulating file sizes with different prefix notations (file size unit conversion)
What it is and what it does
bitmath is a Python library for working with file sizes in different unit systems. It handles conversion between SI units (kB, MB, GB) and NIST binary units (KiB, MiB, GiB, and up to YiB), letting you treat sizes as first-class objects that support arithmetic, comparison, and formatting. The library includes no external dependencies beyond Python's standard library.
You use it when you need to convert between unit systems, perform capacity calculations (like fitting files on a drive), or display file sizes in human-readable form. It supports floor division and modulo for capacity planning (e.g., how many 300 MiB chunks fit in 1 GiB), rich comparisons so 1024 Bytes equals 1 KiB, and integrates with Python's format protocol and argparse for CLI tools.
Use it for:
- Convert storage sizes between SI and NIST units for display or calculation in file management tools.
- Calculate how many files or chunks fit on a device using floor division and modulo operations.
- Format file sizes for human-readable output in logs, reports, or interactive shells.
- Perform arithmetic on sizes (subtract, divide, compare) without manual unit conversion.
- Parse and validate file size input from command-line arguments or user configuration.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
bitmath converts and performs arithmetic on file sizes across SI and NIST prefix units (kB to YiB), with support for human-readable formatting, rich comparisons, and capacity math.
Yes. bitmath is actively maintained, has no dependencies, installs cleanly, carries permissive MIT licensing, and solves a concrete problem—file size unit conversion and arithmetic—that many tools need. Use it whenever you work with storage sizes and want to avoid manual conversion logic or string parsing.
Install
bitmath on PyPI
pip
pip install bitmathuv
uv add bitmathpoetry
poetry add bitmathInstalling bitmath
Before you install
Low friction: pure Python wheel with no runtime dependencies. Actively maintained with a recent release 81 days ago and ongoing repository activity.
License in practice
MIT license permits unrestricted use, modification, and distribution in both open and closed projects with minimal obligations.
Quickstart
pip install bitmath
import bitmath
log_size = bitmath.kB(137.4)
log_zipped = bitmath.Byte(987)
print(log_size - log_zipped)
Requires Python 3.9 or newer.
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 81 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 396,904/month — #6,967 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: bitmath-2.1.1-py3-none-any.whl
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
binaryConverts between binary (IEC) and decimal (SI)…
permissive · top 15,000 on PyPI
hurry.filesizeConverts byte counts into human-readable file…
unclear · top 15,000 on PyPI
prefixedPrefixed provides a Float subclass that formats…
copyleft · top 5,000 on PyPI
django-mathfiltersProvides Django template filters for basic…
permissive · top 15,000 on PyPI
anycrcCalculates CRC hashes of arbitrary bit widths…
permissive · top 15,000 on PyPI
pyroaringProvides an efficient, ordered set data…
permissive · top 1,000 on PyPI
tibsTibs provides immutable and mutable bit-level…
permissive · top 5,000 on PyPI
fxpmathFxpmath provides fixed-point arithmetic with…
permissive · top 15,000 on PyPI
fixedintProvides fixed-width integer classes that…
permissive · top 5,000 on PyPI