{"id":34095043,"url":"https://github.com/biqqles/deconstruct","last_synced_at":"2026-04-01T20:22:11.295Z","repository":{"id":51647811,"uuid":"213254659","full_name":"biqqles/deconstruct","owner":"biqqles","description":"Pythonic C-style structs for parsing binary data","archived":false,"fork":false,"pushed_at":"2022-11-06T23:36:20.000Z","size":30,"stargazers_count":17,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-03-28T00:39:35.324Z","etag":null,"topics":["library"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/deconstruct","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/biqqles.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-06T22:39:47.000Z","updated_at":"2025-03-27T19:54:40.000Z","dependencies_parsed_at":"2023-01-21T06:01:40.276Z","dependency_job_id":null,"html_url":"https://github.com/biqqles/deconstruct","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/biqqles/deconstruct","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/biqqles%2Fdeconstruct","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/biqqles%2Fdeconstruct/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/biqqles%2Fdeconstruct/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/biqqles%2Fdeconstruct/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/biqqles","download_url":"https://codeload.github.com/biqqles/deconstruct/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/biqqles%2Fdeconstruct/sbom","scorecard":{"id":239545,"data":{"date":"2025-08-11","repo":{"name":"github.com/biqqles/deconstruct","commit":"94fb1454bca03d7901a864bdefbb910c324f574b"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.7,"checks":[{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.md:0","Info: FSF or OSI recognized license: Mozilla Public License 2.0: LICENSE.md:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":0,"reason":"Project has not signed or included provenance with any releases.","details":["Warn: release artifact v0.6 not signed: https://api.github.com/repos/biqqles/deconstruct/releases/33590384","Warn: release artifact v0.5 not signed: https://api.github.com/repos/biqqles/deconstruct/releases/25379742","Warn: release artifact v0.4 not signed: https://api.github.com/repos/biqqles/deconstruct/releases/22870092","Warn: release artifact v0.3 not signed: https://api.github.com/repos/biqqles/deconstruct/releases/22725636","Warn: release artifact v0.6 does not have provenance: https://api.github.com/repos/biqqles/deconstruct/releases/33590384","Warn: release artifact v0.5 does not have provenance: https://api.github.com/repos/biqqles/deconstruct/releases/25379742","Warn: release artifact v0.4 does not have provenance: https://api.github.com/repos/biqqles/deconstruct/releases/22870092","Warn: release artifact v0.3 does not have provenance: https://api.github.com/repos/biqqles/deconstruct/releases/22725636"],"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-17T06:26:16.693Z","repository_id":51647811,"created_at":"2025-08-17T06:26:16.693Z","updated_at":"2025-08-17T06:26:16.693Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31291526,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-01T13:12:26.723Z","status":"ssl_error","status_checked_at":"2026-04-01T13:12:25.102Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["library"],"created_at":"2025-12-14T15:07:37.671Z","updated_at":"2026-04-01T20:22:11.260Z","avatar_url":"https://github.com/biqqles.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# deconstruct\n**deconstruct** provides a Pythonic analogue of C's `struct`, primarily for the purpose of interpreting (i.e. _deconstructing_) contiguous binary data.\n  \nInternally, deconstruct uses Python's [struct module](https://docs.python.org/3/library/struct.html) and can be considered an abstraction of sorts. struct (the module) can be frustrating to use: its format strings appear arcane and furthermore separate the description of the data from its representation, a definite strength of C's struct.\n  \nIn contrast, deconstruct allows structs to be defined and used using a syntax that is Pythonic while maintaining close correspondence to C.  \n  \n### Usage  \nWith deconstruct, the struct definition (adapted from [input.h](https://github.com/torvalds/linux/blob/master/include/uapi/linux/input.h)):\n\n```C\n#include \u003cstdint.h\u003e\n\nstruct input_event {  \n    uint64_t time[2];\n    int16_t type;\n    int16_t code;\n    int32_t value;\n};\n```\n\ncan be represented as:\n\n```Python\nimport deconstruct as c\n\nclass InputEvent(c.Struct):\n    time: c.uint64[2]\n    type: c.int16\n    code: c.int16\n    value: c.int32\n```\n\nThis definition can be used to interpret and then access binary data:\n\n```Python\n\u003e\u003e\u003e buffer = b'Some  arbitrary  buffer!'\n\u003e\u003e\u003e event = InputEvent(buffer)\n\u003e\u003e\u003e event.code\n26229\n\u003e\u003e\u003e event.time\n(8241904116577431379, 2340027244253309282)\n\u003e\u003e\u003e print(event)\nstruct InputEvent [ByteOrder.NATIVE, TypeWidth.STANDARD] {\n    time: uint64 = (8241904116577431379, 2340027244253309282)\n    type: int16 = 25120\n    code: int16 = 26229\n    value: int32 = 561145190\n}\n```\n\nOf course, in reality the buffer passed in is more likely to come from something more useful, like a file. Notice that fixed-size, n-dimensional arrays can be specified using the syntax `type[length]`, a further improvement on Python's struct.\n\n### Installation\ndeconstruct is now on PyPI:\n\n```sh\npip install deconstruct\n```\n\nAlternatively you can install straight from this repository:\n\n```sh\npip install https://github.com/biqqles/deconstruct/archive/master.zip\n```\n\nBuilt wheels are also available under [Releases](https://github.com/biqqles/deconstruct/releases), as is a changelog. The latest release is version 0.6.\n\ndeconstruct has no dependencies but requires Python \u003e= 3.6 as it makes use of the class annotation syntax added in that release (see [PEP 526](https://www.python.org/dev/peps/pep-0526/)).\n\n## API listing\n\n### Struct(buffer: bytes)\nSubclass this to define your own structs. Subclasses should only declare fields of C types defined in this package.\n\nWhen you instantiate your Struct with a [bytes-like object](https://docs.python.org/3/glossary.html#term-bytes-like-object), deconstruct creates a format string and uses it to unpack that buffer. In the instance, C types will be replaced with their equivalent Python types for use (e.g. `bytes` for `char`, `int` for `schar` and `float` for `double`). All types available for use in struct field definitions and their details are documented in the table [below](#c-types).\n\n#### Attributes\n|Name            |Type       |Description   |\n|----------------|-----------|--------------|\n|`__byte_order__`|`ByteOrder`|Set this in your subclass definition to define the byte order used when unpacking the struct. One of:\u003cul\u003e\u003cli\u003e`ByteOrder.NATIVE` (default value)\u003c/li\u003e\u003cli\u003e`ByteOrder.BIG_ENDIAN`\u003c/li\u003e\u003cli\u003e`ByteOrder.LITTLE_ENDIAN`\u003c/li\u003e\u003c/ul\u003e|\n|`__type_width__`|`TypeWidth`|Set this in your subclass definition to define the type width and padding used for the struct. One of:\u003cul\u003e\u003cli\u003e`TypeWidth.NATIVE`\u003c/li\u003e\u003cli\u003e`TypeWidth.STANDARD` (default value)\u003c/li\u003e\u003c/ul\u003eWhen `TypeWidth.NATIVE` is set, the struct will use native type widths and alignment. When `TypeWidth.STANDARD` is used, the struct will use Python's struct's \"standard\" widths\u003csup\u003e[1](#f_st)\u003c/sup\u003e and no padding.|\n\nNote that `TypeWidth.NATIVE` can only be used with `ByteOrder.NATIVE`. This is a limitation of Python's struct.\n\n#### Class methods\n|Signature       |Return type|Description   |\n|----------------|-----------|--------------|\n|`new(*args)`    |`Struct`   |Construct a new struct instance with field values specified as positional arguments, passed in order of definition. Note that arguments are not type checked.|\n\n#### Class properties\n|Name            |Type       |Description   |\n|----------------|-----------|--------------|\n|`format_string` |`str`      |The struct.py-compatible format string for this struct|\n|`sizeof`        |`int`      |The total size in bytes of the struct. Equivalent to C's `sizeof`|\n\n#### Instance methods\n|Signature       |Return type|Description   |\n|----------------|-----------|--------------|\n|`to_bytes()`    |`bytes`    |Returns the in-memory (\"packed\") representation of this struct instance|\n|`_require()`    |`bool`     |Override this method to specify your own instance validation logic. This method is called each time the struct is initialised; a `ValueError` will be raised if it returns false.|\n\nYou can also `print` Struct instances for easier debugging and compare them using the `==` operator.\n\n### C types\ndeconstruct defines the following special types for use in Struct definitions:\u003csup\u003e[2](#f_ty)\u003c/sup\u003e\n\n|deconstruct type|C99 type            |Python format character|\"Standard\" width (bytes)\u003csup\u003e[1](#f_st)\u003c/sup\u003e|Resolves to Python type|\n|----------------|--------------------|-----------------------|------------------------|--------------------------------------------|\n|`char`          |`char`              |`c`                    |1                       |`bytes` of length 1                         |\n|`schar`         |`signed char`       |`b`                    |1                       |`int`                                       |\n|`uchar`         |`unsigned char`     |`B`                    |1                       |`int`                                       |\n|`short`         |`short`             |`h`                    |2                       |`int`                                       |\n|`ushort`        |`unsigned short`    |`H`                    |2                       |`int`                                       |\n|`int`           |`int`               |`i`                    |2                       |`int`                                       |\n|`uint`          |`unsigned int`      |`I`                    |2                       |`int`                                       |\n|`long`          |`long`              |`l`                    |4                       |`int`                                       |\n|`ulong`         |`unsigned long`     |`L`                    |4                       |`int`                                       |\n|`longlong`      |`long long`         |`q`                    |8                       |`int`                                       |\n|`ulonglong`     |`unsigned long long`|`Q`                    |8                       |`int`                                       |\n|`bool`          |`bool` (`_Bool`)    |`?`                    |1                       |`bool`                                      |\n|`float`         |`float`             |`f`                    |4                       |`float`                                     |\n|`double`        |`double`            |`d`                    |8                       |`float`                                     |\n|`int8`          |`int8_t`            |`b`*                   |1                       |`int`                                       |\n|`uint8`         |`uint8_t`           |`B`*                   |1                       |`int`                                       |\n|`int16`         |`int16_t`           |`h`*                   |2                       |`int`                                       |\n|`uint16`        |`uint16_t`          |`H`*                   |2                       |`int`                                       |\n|`int32`         |`int32_t`           |`l`*                   |4                       |`int`                                       |\n|`uint32`        |`uint32_t`          |`L`*                   |4                       |`int`                                       |\n|`int64`         |`int64_t`           |`q`*                   |8                       |`int`                                       |\n|`uint64`        |`uint64_t`          |`Q`*                   |8                       |`int`                                       |\n|`ptr`           |`void*`/`intptr_t`/`uintptr_t`|`P`          |N/A**                   |`int`                                       |\n|`size`          |`size_t`            |`n`                    |N/A**                   |`int`                                       |\n|`ssize`         |`ssize_t`           |`N`                    |N/A**                   |`int`                                       |\n\n\u003csup\u003e\n* format character with \u003ccode\u003e__type_width__ = TypeWidth.STANDARD\u003c/code\u003e - platform specific otherwise.\u003cbr\u003e\n** only available with \u003ccode\u003e__type_width__ = TypeWidth.NATIVE\u003c/code\u003e.\n\u003c/sup\u003e\n\n### Arrays\nAs mentioned earlier, all the types above support a `type[length]` syntax to define arrays. Multidimensional arrays work as you would expect, with `int[2][2]` declaring a 2-D array of type `int` and total length 4. When a Struct is used to unpack a buffer, each array will resolve to a tuple (or in the case of a multidimensional array, a nested tuple) of their equivalent Python types, as documented in the table above. The only exception to this is `char`, an array of which will be automatically concatenated to a single `bytes` object (if this behaviour is undesirable, use `schar` or `uchar` instead).\n\n### Pointers\n`ptr` uniquely supports an optional notation format using the `\u003e` operator, allowing you to denote the type it points to. This notation is purely for programmer convenience - it, for example, has no effect on the size of the struct as all pointers are assumed to be of the size of `void*` (which is guaranteed to be able to hold any pointer).\n\nTo illustrate this syntax, `f: c.ptr \u003e c.double` denotes a pointer to double (`double* f;`). Arrays of pointers *and* pointers to arrays are supported. For example, `c.ptr[2] \u003e c.int` indicates an array of `int*`, while `c.ptr \u003e c.int[2]` indicates a pointer to an `int` array.\n\nYou can also use `Struct` subtypes as the pointed-to type.\n\n---\n\n\u003cb id=\"f_st\"\u003e1.\u003c/b\u003e Python's struct has the concept of \"standard\" type sizes. This is somewhat confusing coming from C as its standards go to some length not to define a standard ABI. However, as this terminology is so fundamental to the documentation of Python's struct it is replicated here for simplicity's sake. These sizes correspond with the *minimum* sizes [implied](https://en.wikipedia.org/wiki/C_data_types#Basic_types) for C's types.\t\n\n\u003cb id=\"f_ty\"\u003e2.\u003c/b\u003e Because some of these conflict with Python's primitives, it is not recommended to `from deconstruct import *` as this will severely pollute your namespace (in fact this is a bad idea in general). I like to `import deconstruct as c` as shown above.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbiqqles%2Fdeconstruct","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbiqqles%2Fdeconstruct","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbiqqles%2Fdeconstruct/lists"}