Skip to main content

Tiny library to parse binary structures into Python objects

Project description

Destruct is a tiny library to declaratively define data structures and parse them to Python objects.

The library is not mature by any means. Things may break, and API may significantly change in future.

https://secure.travis-ci.org/drdaeman/destruct.png?branch=master

Example

Data structures are declared in a manner somehow similar to Django models:

from destruct import StructBase
import destruct.fields as f

class MyStruct(StructBase):
    timestamp = f.TimestampField()
    value = f.U32Field()

Then, parsing is just creating object:

data = MyStruct(b"\0\0\0\0\0\0\0\xFF")
assert data.timestamp == datetime.datetime.utcfromtimestamp(0)
assert data.value == 255

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

destruct-0.1.0.tar.gz (4.8 kB view details)

Uploaded Source

File details

Details for the file destruct-0.1.0.tar.gz.

File metadata

  • Download URL: destruct-0.1.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for destruct-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c8f1f972e2617e5a01841876a78211d024037b050712bf7737fd670717783cae
MD5 434676d9a560068b48f5f15bbc084459
BLAKE2b-256 dd414d3c211b512b79c47cb0247c92f2c2f874005d785148a87b9052b3699300

See more details on using hashes here.

Supported by

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