Registry / devops / pycstruct

pycstruct

JSON →
library0.12.2pypypi✓ verified 86d ago

Binary data handling in Python using dictionaries. Current version 0.12.2, stable and infrequently updated.

pip install pycstruct
INSTALL
IMPORT
SIG · PYCSTRUCT
P
pycstruct
devopspythonv0.12.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pycstruct
import pycstruct
from pycstruct import *
Star imports are discouraged; use explicit imports.
Struct
from pycstruct import Struct
Common pattern to directly use the Struct class.

Basic example of defining a struct, packing, and unpacking binary data.

import pycstruct # Define a simple struct template = { 'field1': 'u8', 'field2': 's16', 'field3': 'u32' } # Create a Struct instance my_struct = pycstruct.Struct(template) # Pack data binary_data = my_struct.pack({'field1': 255, 'field2': -123, 'field3': 100000}) # Unpack unpacked = my_struct.unpack(binary_data) print(unpacked)
Debug
Known issues
gotchaThe Struct class does not automatically handle endianness; you must specify byte order using '>' (big) or '<' (little) in field definitions, e.g., '>u16'.
fix
Prefix field types with '>' or '<' to set endianness, e.g., {'field': '>u16'}.
affects: all
gotchaField names must be strings; pycstruct does not support nested structs directly; you must flatten structures or use repeated fields.
fix
Use a flat dictionary or combine multiple Struct instances manually.
affects: all
deprecatedThe use of 's' (string) field type is deprecated in favor of explicit byte array types like 'bytes'.
fix
Use 'bytes' type with length, e.g., {'data': 'bytes(4)'} instead of {'data': 's4'}.
affects: >=0.10
Errors
Common errors & fixes
AttributeError: module 'pycstruct' has no attribute 'Struct'
Trying to use pycstruct.Struct after installing an older version (pre-0.10) where the class was named differently.
fix
Make sure you have version >=0.10 and use from pycstruct import Struct.
ValueError: invalid literal for int() with base 10: b'...'
Attempting to unpack binary data without specifying the correct byte order or type.
fix
Ensure the template's field types match the binary layout and add endianness prefix if needed.
Upgrade
Version history
0.12.2latest on PyPI · released Mar 24, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
pycstruct — pip install pycstruct · libregistry