plum-py
raw JSON → 0.8.7 verified Fri May 01 auth: no python
Pack/Unpack Memory. A Python library for packing and unpacking binary data structures, similar to struct but with higher-level features. Current version 0.8.7, release cadence is low (last release August 2022).
pip install plum-py Common errors
error ImportError: No module named 'plum_py' ↓
cause Trying to import with the PyPI package name instead of the module name.
fix
Use 'import plum' or 'from plum import Struct'.
error TypeError: __init__() got an unexpected keyword argument 'field_name' ↓
cause Attempting to set fields via constructor with Python-typed field names, but the library expects specific names derived from format strings.
fix
Ensure field names match class attributes defined with format strings.
Warnings
gotcha The import is 'from plum import Struct', not 'plum-py' or 'plum_py'. The PyPI name is plum-py but the module name is plum. ↓
fix Use 'from plum import Struct'.
gotcha Field types are specified as strings (e.g., 'I' for unsigned int) similar to struct module. Using Python type hints does not work; you must use struct format characters. ↓
fix Define fields as class-level annotations with format strings, e.g., field_name: 'I'.
gotcha The Struct class does not support variable-length arrays or nested structs directly. Use custom pack/unpack methods. ↓
fix For complex structures, consider using construct or raw struct.
Imports
- Struct wrong
from plum_py import Structcorrectfrom plum import Struct
Quickstart
from plum import Struct
class MyHeader(Struct):
magic: 'I' # unsigned int
length: 'I'
data: 'I'
hdr = MyHeader(magic=0x1234, length=100, data=0)
buffer = hdr.pack()
print(buffer.hex())