{"id":21066,"library":"construct-classes","title":"construct-classes","description":"Parse binary structs defined with the `construct` library into Python dataclasses. Version 0.2.3 requires Python >=3.10, <4.0. Active development.","status":"active","version":"0.2.3","language":"python","source_language":"en","source_url":"https://github.com/matejcik/construct-classes","tags":["binary","parsing","dataclasses","construct","struct"],"install":[{"cmd":"pip install construct-classes","lang":"bash","label":"Install via pip"}],"dependencies":[{"reason":"construct-classes builds on construct for binary parsing","package":"construct","optional":false}],"imports":[{"note":"Wrong: the function is named construct_dataclass, not dataclass","wrong":"from construct_classes import dataclass","symbol":"construct_dataclass","correct":"from construct_classes import construct_dataclass"},{"note":"Struct is from the `construct` library, not construct-classes","wrong":"from construct_classes import Struct","symbol":"Struct","correct":"from construct import Struct"}],"quickstart":{"code":"from construct import Struct, Int32ul, Hex, Int8ul\nfrom construct_classes import construct_dataclass\n\n@construct_dataclass\nclass MyStruct:\n    x: int = Int32ul\n    y: int = Hex(Int8ul)\n\n# Parse binary data\ndata = b'\\x01\\x00\\x00\\x00\\x02'\nobj = MyStruct.parse(data)\nprint(obj.x, obj.y)","lang":"python","description":"Define a dataclass with construct fields and parse binary data."},"warnings":[{"fix":"Ensure fields are in correct order, e.g., if struct has [Int32ul, Int8ul], declare x first then y.","message":"Field order matters: fields must be declared in the same order as in the binary struct. The dataclass field order defines the parse order.","severity":"gotcha","affected_versions":"all"},{"fix":"Use construct subcon syntax: field: type = Subcon(InnerSubcon()). For Hex, use Hex(Int8ul).","message":"Subcon fields: when using subconstructs (e.g., Hex, BytesInteger), you must wrap them correctly. Hex(Int8ul) works, but wrong usage causes cryptic errors.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Add @construct_dataclass above the class definition.","cause":"The class is not decorated with @construct_dataclass, so it lacks the .parse() method.","error":"AttributeError: 'MyStruct' object has no attribute 'parse'"},{"fix":"Ensure the binary data has enough bytes. For Int32ul, provide at least 4 bytes.","cause":"Insufficient binary data passed to .parse(). The binary data length is shorter than the struct expects.","error":"construct.core.StreamError: could not parse, expected 4 bytes, got 0"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}