title: Reading Structure Binary Data in Python?
body: <p>Are there any nice Python solutions like Ruby's <a href="http://bindata.rubyforge.org/manual.html" rel="nofollow">BinData</a> for reading user-defined binary file/stream formats? If not, then what's the preferred way to this in Python outside of just using the <a href="https://docs.python.org/2/library/struct.html" rel="nofollow">struct</a> module?</p>
  
  <p>I have a binary file that stores "records" of events. The records are dynamic in size, so I must read the first few bytes of each record to determine the record length and record type. Different record types will have different byte layouts. For instance, a record of type "warning" might contain three 4-byte ints, followed by a 128 byte value, while a record of type "info" might just have five 4-byte ints. </p>
  
  <p>It would be nice to define the different record types and their structures in such a way that I could simply pass a binary blob to something, and it handle the rest (object generation, etc). In short, your defining templates/maps on how to interpret binary data.</p>