Nearly eight years after 1.3.3 shipped in 2018, bitmath is back with a major release. Version 2.0.0 is a thorough modernization: the Python 2 era is officially over, the library picks up several long-requested features, and the entire project infrastructure has been rebuilt from scratch. If you've been running bitmath on anything from Python 3.11 onward and quietly wishing it felt more modern — this release is for you.
| Area | What changed |
|---|---|
| Python support | Python 3.11+ only. Python 2 and Python 3.7–3.10 are no longer supported or tested. |
parse_string() default |
The default unit system when strict=False is now NIST (binary). Previously it defaulted to SI. Code that relied on the old default for ambiguous strings like "1g" will get a different result. |
parse_string_unsafe() |
Deprecated. Use parse_string(strict=False) instead. The old name still works but emits a DeprecationWarning. |
bitmath.integrations |
The argparse, click, and progressbar integrations have been removed from the package entirely. Copy-paste replacements are provided in the new Integration Examples documentation chapter — they require no changes to calling code, just a local copy. |
| Build / install | setup.py and setup.py.in are gone. Installation is pip install bitmath. Source builds use python -m build. |
The core API is unchanged — every bitmath object you created before still works exactly the same way. What 2.0.0 adds on top of that:
Full NIST unit coverage. The four largest NIST prefix units — ZiB, YiB, Zib, and Yib — are now first-class bitmath types. All constants (NIST_PREFIXES, NIST_STEPS, ALL_UNIT_TYPES) reflect reality.
f-string and format() support. bitmath objects now implement the Python format protocol (__format__, PEP 3101). You can use them directly in f-strings with format specs: f"{some_size:.2f}" just works. Credit to Jonathan Eunice for the original concept in PR #76.
bitmath.sum() and built-in sum(). A new bitmath.sum() function returns a unit-normalised result when summing mixed-type iterables. For uniform collections, the built-in sum() now works directly on bitmath sequences without a start= argument.
Thread-safe context manager. The bitmath.format() context manager previously mutated module-level globals, making it unsafe to use from multiple threads simultaneously. It now uses threading.local with proper save/restore semantics, including correct nesting behavior. Closes issue #83.
best_prefix() bug fix. best_prefix() incorrectly converted bit-family units (e.g., Kib) into byte-family units (e.g., KiB). The unit family is now preserved. Closes issue #95.
Flexible string parsing. parse_string(strict=False) accepts ambiguous input like "1g" or "1GB" and resolves it to the most likely unit. When the system is genuinely ambiguous, NIST is the tiebreaker. Closes issue #54.
The project infrastructure has been rebuilt to reflect how Python projects are actually maintained in 2026:
- Packaging —
pyproject.tomlwith a hatchling backend replaces the oldsetup.py/setup.py.intemplate system. The package is PEP 517/PEP 518 compliant.MANIFEST.inis gone; sdist content is declared explicitly inpyproject.toml. - GitHub Actions — CI now runs against Python 3.11, 3.12, and 3.13 on both Ubuntu and macOS. Actions are pinned to current versions (
checkout@v4,setup-python@v5). Tests run on every pull request, not just pushes. - Security scanning — CodeQL analysis runs on every push to master, every pull request, and on a weekly schedule.
- ReadTheDocs —
.readthedocs.yamlis now present and explicit. The RTD build uses Python 3.11 and installssphinx_rtd_themedirectly. - Development workflow —
make ciis the single command for a full local build: unique test name check, pycodestyle, flake8, pytest with coverage.make build,make pypitest, andmake pypireplace the oldmake sdist uploadpattern.
bitmath started as a small passion project of mine. A utility for thinking about and clearly expressing file sizes, and that's still exactly what it is. This 2.0.0 release doesn't change what the library does. What I've done is change the very foundation that it's built on. The test suite sits at 288 tests and 100% coverage. The documentation has been comprehensively reviewed and updated. The packaging is clean enough to pass twine check on the first attempt (well, the second).
It really is a remarkable milestone in project history. I have to give the warmest thanks to all of the users and fans who have written bug reports and submitted pull requests. Especially in the least active years of the project. Most of those PRs and Issues have been integrated into this massive 2.0 release.
Thanks for your patience and your participation.
If you've been holding off on adopting bitmath because the last release predated your Python version — yeah I totally get it. This place was a dumpster for the last 8 years.
Go on, give it a shot. It really is better than ever.