bitstring is a Python library to help make the creation and analysis of all types of bit-level binary data as simple and efficient as possible. It has been actively maintained since 2006.
[!NOTE]
To see what's been added, improved or fixed, see the release notes.
Version 5.0
This is a major update with breaking changes.
Significantly better performance using the new tibs Rust core - around 4x faster across the benchmark suite, and far more for bulk Array work, searching and packing.
A simpler model for sequential reading: Bits and BitArray store data, while Reader stores the current bit position.
A clearer, more explicit API for construction, conversion and dtype names.
Some things have also been removed, including the bitarray dependency, LSB0 mode and the old stream classes.
Upgrading from version 4
Version 5 is worth moving to if you need the improved performance, want the cleaner API and other new features.
The changes are quite broad, so if your existing code is stable and performance
is not a problem, there is no need to migrate immediately - pin your dependency to to stay on 4.x.
The 4.x line is maintained on the branch.
What's this 'tibs' thing that everyone is talking about?
bitstring 5 is built on tibs, a more focussed Python library for
binary data, written in Rust and highly optimised for speed. It's by the same author as bitstring.
For new projects, starting with tibs could be a better choice in many cases.
Tibs has now reached its 2.0 release. Please do try it, as all feedback is welcome.
A sleek Python library for binary data
Bitstring Overview
Efficiently store and manipulate binary data in idiomatic Python.
Create bitstrings from hex, octal, binary, files, formatted strings, bytes, integers and floats of different endiannesses.
Powerful binary packing and unpacking functions.
Bit-level slicing, joining, searching, replacing and more.
Create and manipulate arrays of fixed-length bitstrings.
Use Reader to read from and interpret bitstrings sequentially.
Rich API - chances are that whatever you want to do there's a simple and elegant way of doing it.
Open source software, released under the MIT licence.
Documentation
Extensive documentation for the bitstring library is available.
Some starting points: