bitstring is a pure Python module that makes the creation, manipulation and analysis of binary data as simple and natural as possible.

It has been maintained since 2006 and now has about 20 million downloads per year.

You can try out an interactive walkthrough notebook on binder (or the non-interactive version here).



  • 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.

  • Read from and interpret bitstrings as streams of binary data.

  • Rich API - chances are that whatever you want to do there’s a simple and elegant way of doing it.

  • Supports Python 3.7 and later. Use bitstring version 3 for Python 2.7 and 3.x support.

  • Open source software, released under the MIT licence.

A short example usage

>>> s = bitstring.BitArray('0x4f8e220')
>>> s.unpack('uint12, hex8, bin')
[1272, 'e2', '00100000']
>>> '0b11000' in s
>>> s += 'f32=0.001'
>>> s.bin
>>> s[-32:].float

Installation and download

To install just pip install bitstring.

To download the module, as well as for defect reports, enhancement requests and Git repository browsing go to the project’s home on GitHub.


The User Manual provides an introduction to the module and details most its capabilities.

The Reference section has a complete list of all the classes, methods, properties and functions of the bitstring module, together with short examples for many items.


Created by Scott Griffiths in 2006 to help with ad hoc parsing and creation of compressed video files. Maintained and expanded ever since as it became unexpectedly popular. Thanks to all those who have contributed ideas and code (and bug reports) over the years.

These docs are styled using the Piccolo theme.