_images/bitformat_logo.png

A Python library for creating and parsing binary formats.


  • Efficiently store and manipulate binary data in idiomatic Python using the Bits, MutableBits and Array classes.

  • Powerful binary packing and unpacking functions.

  • Bit-level slicing, joining, searching, replacing and more.

  • A wide array of data types is supported. Want to use a 13-bit integer or a 16-bit float? Fine - there are no special hoops to jump through.

  • Several field types are available to build up a Format, which can then be used to pack, unpack or parse data:

    • The simplest is just a Field which contains an optionally named value with a data type.

    • A Format contains a list of other fields. These can be nested to any depth.

    • Field types like Repeat and If can be used to add more logical structure.

  • The values of fields can be used in later calculations via an f-string-like expression syntax.

  • Data is always stored efficiently as a contiguous array of bits, with the core of the library written in Rust.

It is from the author of the bitstring library.


Documentation

The introduction covers installation and a few brief examples, but doesn’t go into much depth.

We then explore many of the features of the library via some common use cases.

The API reference is more comprehensive and is mostly generated from the docstrings in the library. Some introductory notes are included in each section.

There is also a notebook with a tour of the features of bitformat:


These docs are styled using the Piccolo theme.