Released: April 25, 2026
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 Python 3.9 or later and quietly wishing it felt more modern — this release is for you.
Check over on my blog for a personal recap of this release, how much it means to me, and what it took to get here.
- Python support
- Python 3.9+ only. Python 2 and Python < 3.9 are no longer supported or tested.
- parse_string() default system
- The default unit system when
strict=Falseis now NIST (base-2). Previously it defaulted to SI (base-10). Code that relied on the old default for ambiguous strings such as"1g"could get a different result. See :ref:`parse-string-non-strict` for full details. All bitmath now consistently defaults to the NIST system. - parse_string_unsafe() deprecated
- Use :func:`bitmath.parse_string` with
strict=Falseinstead. The old name still works but emits a :exc:`DeprecationWarning`. - bitmath.integrations removed
- The
argparse,click, andprogressbarintegrations have been removed from the package. Copy-paste replacements are provided in the new :ref:`Integration Examples <integration_examples>` documentation chapter. No changes to calling code are required — just a local copy of the relevant snippet. - Byte and Bit display names
ByteandBitnow display asBandbrespectively, matching the abbreviated style of every other unit. Code that compares formatted strings (e.g."{unit}"in a format template or the output ofstr()/repr()) against the literal words"Byte"or"Bit"will need to be updated. The class names themselves are unchanged.- query_device_capacity() on macOS
- :func:`bitmath.query_device_capacity` now raises :exc:`NotImplementedError` on macOS. System Integrity Protection (SIP) blocks raw block device access even for root, making the previous ioctl path unreliable. Use :func:`bitmath.query_capacity` instead.
- Build and install
setup.pyandsetup.py.inare gone. Installation ispip install bitmath. Source builds usepython -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 — :class:`~bitmath.ZiB`, :class:`~bitmath.YiB`, :class:`~bitmath.Zib`, and :class:`~bitmath.Yib` — are now first-class bitmath types. All constants (:ref:`NIST_PREFIXES, NIST_STEPS, ALL_UNIT_TYPES <module_class_variables>`) reflect reality.
- f-string and format() support
- bitmath objects now implement the Python format protocol
(
__format__, PEP 3101). They can be used directly in f-strings with format specs —f"{some_size:.2f}"just works. See :ref:`instances_dunder_format` for the full reference. Credit to Jonathan Eunice for the original concept in PR #76. - bitmath.sum() and built-in sum()
- A new :func:`bitmath.sum` function returns a unit-normalized result
when summing mixed-type iterables. For uniform collections, the
built-in :py:func:`sum` now works directly on bitmath sequences
without a
start=argument. - Thread-safe context manager
- The :func:`bitmath.format` context manager previously mutated
module-level globals, making it unsafe under concurrent access. It
now uses
threading.localwith proper save/restore semantics, including correct nesting behavior. Closes issue #83. - best_prefix() bit-family fix
- :func:`bitmath.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. - query_capacity() — recommended volume size API
- New :func:`bitmath.query_capacity` returns a :class:`bitmath.Capacity`
NamedTuple of
(total, used, free):class:`bitmath.Bitmath` instances for any path or mount point. Works cross-platform without elevated privileges. This is the recommended API for "how big is this volume?" queries. Acceptsbestprefix=True(default) to get already human-readable units (e.g.GiB) andsystem=bitmath.SIto opt into decimal prefixes instead of the default NIST binary prefixes. Setbestprefix=Falseto receive raw :class:`bitmath.Byte` instances. - Windows device capacity
- :func:`bitmath.query_device_capacity` now works on Windows via
DeviceIoControl. Open the device asopen(r'\\.\PhysicalDrive0', 'rb')(administrator privileges required). Unsupported platforms raise :exc:`NotImplementedError`. The new :data:`bitmath.SUPPORTED_PLATFORMS` constant lists all platforms where the function is available. Closes issue #52. - query_device_capacity() Linux buffer fix
- :func:`bitmath.query_device_capacity` on Linux was passing an
integer where an ioctl buffer was required, causing
OSError: [Errno 14] Bad address. The call now correctly allocates a zero-filled buffer of the proper size viab'\\x00' * struct.calcsize(fmt). - Flexible string parsing
- :func:`bitmath.parse_string` with
strict=Falseaccepts ambiguous input such as"1g"or"1GB"and resolves it to the most likely unit. When the system cannot be reliably determined, NIST is the tiebreaker. Closes issue #54. - Floor division, modulo, and divmod for capacity math
- bitmath objects now implement
__floordiv__(//),__mod__(%), and__divmod__— useful for chunk-and-remainder capacity planning ("how many N-sized chunks fit into this device, and how much is left over?").bm1 // bm2returns anint(count of whole divisions), mirroring howbm1 / bm2returns a unitless ratio.bm1 % bm2anddivmod(bm1, bm2)return remainders as bitmath objects of the left-hand operand's type, consistent with every other bitmath arithmetic operator. The identity(a // b) * b + (a % b) == aholds. See :ref:`capacity_math` for worked examples includingbest_prefix()coercion andbitmath.formatcontext-manager integration.
The project infrastructure has been rebuilt to reflect how Python projects are actually maintained in 2026:
- Project Security
- GitHub now has branch protection enabled. Releases are signed with the maintainers GPG key.
- 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.9 through 3.13 on Ubuntu, macOS, and
Windows, with actions pinned to current versions (
checkout@v6,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, and pytest with coverage.make build,make pypitest, andmake pypireplace the oldmake sdist uploadpattern.- Fedora/EPEL
- Expect to see fresh builds in Fedora/EPEL over the coming weeks. Hopefully I can sneak this into EPEL 10, EPEL 9 might be picky since this is a major version change.
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 measures in at 311 tests now, basically 100% coverage when you add all the platform-specific checks together. The documentation has been comprehensively reviewed and updated. The packaging is modernized.
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.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.
bitmath-1.4.0 was published on 2026-04-16.
Version 1.4.0 is a maintenance release — the final release to support Python 2 era packaging infrastructure. It addresses two long-standing issues and makes no breaking changes.
Bug Fixes
- Fixed packaging:
bitmath.integrationssubpackage was missing from thepackageslist insetup.py.in, causing the argparse, click, and progressbar integrations to be absent from installed distributions. Reported in PR #107. - Modernized mock imports in the test suite:
tests/test_progressbar.pyandtests/test_query_device_capacity.pynow preferunittest.mock(stdlib, Python 3.3+) and fall back to the third-partymockpackage. Based on PR #105.
bitmath-1.3.3-1 was published on 2018-08-23.
Version 1.3.3 is a minor update primarily released to synchronize versions across platforms. Additionally there are small packaging updates to keep up with changing standards.
Minor bug fixes and documentation tweaks are included as well.
The project now has an official Code of Conduct, as well as issue and pull request templates.
What happened to bitmath 1.3.2? It only ever existed as an idea in source control.
Bug Fixes
Alexander Kapshuna has submitted several fixes since the last release. Thanks!
- Packaging requirements fixes
- Python 3 compatibility
- Subclassing and Type checking fixes/improvements
Marcus Kazmierczak submitted a fix for some broken documentation links.
And Dawid Gosławski make sure our documentation is accurate.
Thanks to all the bitmath contributors over the years!
bitmath-1.3.1-1 was published on 2016-07-17.
Added Functionality
- New function: :func:`bitmath.parse_string_unsafe`, a less strict version of :func:`bitmath.parse_string`. Accepts inputs using non-standard prefix units (such as single-letter, or mis-capitalized units).
- Inspired by @darkblaze69's request in #60 "Problems in parse_string".
Ubuntu
- Bitmath is now available for installation via Ubuntu Xenial, Wily, Vivid, Trusty, and Precise PPAs.
- Ubuntu builds inspired by @hkraal reporting an installation issue on Ubuntu systems.
Documentation
- Cleaned up a lot
of broken or re-directing links using output from the Sphinx
make linkcheckcommand.
bitmath-1.3.0-1 was published on 2016-01-08.
Bug Fixes
- Closed GitHub Issue #55 "best_prefix for negative values". Now :func:`bitmath.best_prefix` returns correct prefix units for negative values. Thanks mbdm!
bitmath-1.2.4-1 was published on 2015-11-30.
Added Functionality
- New bitmath module function: :func:`bitmath.query_device_capacity`. Create :class:`bitmath.Byte` instances representing the capacity of a block device. Support is presently limited to Linux and Mac.
- The :func:`bitmath.parse_string` function now can parse 'octet' based units. Enhancement requested in #53 parse french unit names by walidsa3d.
Bug Fixes
- #49 - Fix handling unicode input in the bitmath.parse_string function. Thanks drewbrew!
- #50 - Update the
setup.pyscript to be python3.x compat. Thanks ssut!
- The project documentation is now installed along with the bitmath library in RPM packages.
Fedora/EPEL
Look for separate python3.x and python2.x packages coming soon to Fedora and EPEL. This is happening because of the initiative to update the base Python implementation on Fedora to Python 3.x
bitmath-1.2.3-1 was published on 2015-01-03.
Added Functionality
- New utility:
progressbarintegration: bitmath.integrations.BitmathFileTransferSpeed. A more functional file transfer speed widget.
- The command-line
bitmathtool now has online documentation - A full demo of the
argparseandprogressbarintegrations has been written. Additionally, it includes a comprehensive demonstration of the full capabilities of the bitmath library. View it in the Real Life Demos Creating Download Progress Bars example.
Tests
- Travis-CI had some issues with installing dependencies for the 3.x build unittests. These were fixed and the build status has returned back to normal.
bitmath-1.2.0-1 was published on 2014-12-29.
Added Functionality
- New utility:
argparseintegration: bitmath.BitmathType. Allows you to specify arguments as bitmath types.
- The command-line
bitmathtool now has a proper manpage
Tests
- The command-line
bitmathtool is now properly unittested. Code coverage back to ~100%.
bitmath-1.1.0-1 was published on 2014-12-20.
Added Functionality
- New
bitmathcommand-line tool added. Provides CLI access to basic unit conversion functions - New utility function bitmath.parse_string for parsing a human-readable string into a bitmath object. Patch submitted by new contributor tonycpsu.
bitmath-1.0.8-1 was published on 2014-08-14.
- bitmath has a proper documentation website up now on Read the Docs, check it out: bitmath.readthedocs.io
- bitmath is now Python 3.x compatible
- bitmath is now included in the Extra Packages for Enterprise Linux EPEL6 and EPEL7 repositories (pkg info)
- merged 6 pull requests from 3 contributors
- fixed some math implementation bugs
Added Functionality
- best-prefix guessing: automatic best human-readable unit selection
- support for bitwise operations
- formatting customization methods (including plural/singular selection)
- exposed many more instance attributes (all instance attributes are usable in custom formatting)
- a context manager for applying formatting to an entire block of code
- utility functions for sizing files and directories
- add instance properties
equivalent to
instance.to_THING()methods
Tests
- Test suite is now implemented using Python virtualenv's for consistency across across platforms
- Test suite now contains 150 unit tests. This is 110 more tests than the previous major release (1.0.4-1)
- Test suite now runs on EPEL6 and EPEL7
- Code coverage is stable around 95-100%
This is the first release of bitmath. bitmath-1.0.4-1 was published on 2014-03-20.
Available via:
- PyPi
- Fedora 19
- Fedora 20
bitmath had been under development for 12 days when the 1.0.4-1 release was made available.
- Converting between SI and NIST prefix units (
GiBtokB) - Converting between units of the same type (SI to SI, or NIST to NIST)
- Basic arithmetic operations (subtracting 42KiB from 50GiB)
- Rich comparison operations (
1024 Bytes == 1KiB) - Sorting
- Useful console and print representations