You may want to take a look at https://gitlab.com/kaitaiStructCompile.py/kaitaiStructCompile.py And the example how it can be done: https://gitlab.com/KOLANICH/MFCTool.py or https://gitlab.com/KOLANICH/pyxgboost