Library for parsing binary structures

Paul Moore p.f.moore at gmail.com
Wed Mar 27 14:41:40 EDT 2019


I'm looking for a library that lets me parse binary data structures.
The stdlib struct module is fine for simple structures, but when it
gets to more complicated cases, you end up doing a lot of the work by
hand (which isn't that hard, and is generally perfectly viable, but
I'm feeling lazy ;-))

I know of Construct, which is a nice declarative language, but it's
either weak, or very badly documented, when it comes to recursive
structures. (I really like Construct, and if I could only understand
the docs better I may well not need to look any further, but as it is,
I can't see anything showing how to do recursive structures...) I am
specifically trying to parse a structure that looks something like the
following:

Multiple instances of:
  - a type byte
  - a chunk of data structured based on the type
    types include primitives like byte, integer, etc, as well as
    (type byte, count, data) - data is "count" occurrences of data of
the given type.

That last one is a list, and yes, you can have lists of lists, so the
structure is recursive.

Does anyone know of any other binary data parsing libraries, that can
handle recursive structures reasonably cleanly?

I'm already *way* past the point where it would have been quicker for
me to write the parsing code by hand rather than trying to find a
"quick way", so the questions, honestly mostly about finding out what
people recommend for jobs like this rather than actually needing
something specific to this problem. But I do keep hitting the need to
parse binary structures, and having something in my toolbox for the
future would be really nice.

Paul



More information about the Python-list mailing list