skillfed

bitmath

Pythonic module for representing and manipulating file sizes with different prefix notations (file size unit conversion)

bitmath v2.1.1 396.9K downloads/30d#6,967 on PyPI96
Permissive license Active released

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 bitmath

uv

uv add bitmath

poetry

poetry add bitmath

Installing 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

Development Status :: 5 - Production/StableEnvironment :: ConsoleIntended Audience :: DevelopersIntended Audience :: Information TechnologyIntended Audience :: System AdministratorsIntended Audience :: Telecommunications IndustryLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.9Topic :: Communications :: File SharingTopic :: InternetTopic :: Scientific/EngineeringTopic :: Scientific/Engineering :: Information AnalysisTopic :: Scientific/Engineering :: MathematicsTopic :: Software Development :: LibrariesTopic :: Software Development :: Libraries :: Python ModulesTopic :: Software Development :: TestingTopic :: Software Development :: Testing :: AcceptanceTopic :: Software Development :: Testing :: UnitTopic :: System :: FilesystemsTopic :: System :: Systems AdministrationTopic :: Text Processing :: FiltersTopic :: Utilities

Tags

file size unit conversionbyte size arithmeticSI NIST prefix conversionhuman readable file sizesstorage capacity mathGiB MiB KiB conversionfile size formatting
file-size-conversionunit-conversionstorage-math

More Libraries packages