Skip to main content

Binary protocol parser

Project description

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 :

import dumpy.types as dt

class PString(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.
assert s['len'] == 4

assert s.pack() == b'\x04\x01\x02\x03\x04'

s2 = s.unpack(s.pack())
assert s2['len'] == 4
assert bytes(s2['data']) == b'\x01\x02\x03\x04'

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

Known Issues

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

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dumpy-0.1.1.tar.gz (7.1 kB view details)

Uploaded Source

File details

Details for the file dumpy-0.1.1.tar.gz.

File metadata

  • Download URL: dumpy-0.1.1.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for dumpy-0.1.1.tar.gz
Algorithm Hash digest
SHA256 89e1f479200dbf4a29bfb53962c3bc8abd09a465733b8b213d2106e7af97b3dc
MD5 1edcbb6cc69574ff56f704fff16fd46e
BLAKE2b-256 0c98d75d96d2cdd58bbda881ee19ac9ae5dd424479122f93cf70f00b54f0c4f2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page