Skip to content


Repository files navigation

Python PyPI version Downloads Mkdocs status Travis Build Status Appveyor Build status


A Python library to manage binary data as bitstreams.


Bitstream three main features:

  • It is easy to use since the bitstream abstraction is simple.

  • It works seamlessly at the bit and byte level.

  • It supports Python, NumPy and user-defined types.

See the documentation Overview section for more details.


Make sure that Python 2.7 or Python 3.6 to 3.9 are installed and that pip, NumPy and a C compiler are available, then install bitstream with

$ pip install bitstream

For more details, refer to the documentation.


First, the mandatory "Hello World!" example:

>>> from bitstream import BitStream
>>> BitStream(b"Hello World!")

The basic API is made of three methods only:

  • stream = BitStream() to create an empty stream.

  • stream.write(data, type) to write data data of type type.

  • data =, n) to read n items of type type.

For example:

>>> stream = BitStream()        # <empty>
>>> stream.write(True, bool)    # 1
>>> stream.write(False, bool)   # 10
>>> from numpy import int8
>>> stream.write(-128, int8)    # 1010000000
>>> stream.write(b"AB", bytes)  # 10100000000100000101000010
>>>, 2)        # 100000000100000101000010
[True, False]
>>>, 1)        # 0100000101000010
array([-128], dtype=int8)
>>>, 2)       # <empty>

Refer to the documentation Overview section for more elementary examples.


Refer to Contributing in the documentation.


If you need some support with bitstream and you haven't found a solution to your problem in the documentation, please open an issue in the GitHub issue tracker.

If you don't feel like you problem belongs there, you can send me an e-mail instead; please include "bitstream" in the subject. You will find my e-mail address in my GitHub profile.

In both cases, you will need to sign into GitHub (and join GitHub if you don't already have an account).


Bitstream is open source software released under the MIT license.

Copyright (c) 2012-2023 Sébastien Boisgérault