Navigation

Meta

Maintainers

Classifiers

Dumpy

Dumpy is a binary parser with a declarative syntax. All you need to
do is telling the framework what your data look like, and let Dumpy
do the rest.

Dumpy supports python versions >= 3.0.

Installing

Just use pip or tools alike:

pip install dumpy

Usage

To parse a pre-defined binary structure, you need to define a class
for that structure. For example, a class for pascal strings :

importdumpy.typesasdtclassPString(dict,metaclass=dt.DumpyMeta):__field_specs__=(dt.field('len',dt.UInt8,default=dt.count_of('data')),dt.field('data',dt.UInt8,count=dt.counted_by('len')),)s=PString()s['data']=b'\x01\x02\x03\x04'# The length field is calculated automatically.asserts['len']==4asserts.pack()==b'\x04\x01\x02\x03\x04's2=s.unpack(s.pack())asserts2['len']==4assertbytes(s2['data'])==b'\x01\x02\x03\x04'

See demo/png_packer.py for a real-world format parser.

Known Issues

The type checking and conversion code in Dumpy is kind of naive,
It does not check element types in a sequence.

Dumpy is very slow at current stage. You may not want to use
it to parse network messages or huge data structures.