I ran into this problem many times both at work and in personal projects. I often have data coming from hardware or controllers over UDP, usually written in C/C++, but for testing, debugging, or quick visualization I want to work with simple Python scripts.

I couldn’t really find a tool that does direct translation from C-like structs into Python classes. The usual workaround was basically feeding structs into ChatGPT. That kind of works, but it has two real downsides. First, it’s not great from a safety perspective to paste even “harmless” parts of source code into an external ML tool. The structs themselves usually don’t contain any meaningful logic, but still. Second, the generated code is often messy and inconsistent, and whenever the struct changes, updating everything becomes annoying very quickly. On top of that, parsing the resulting Python-side data into something clean and usable was always ugly and repetitive.

So I ended up building a small tool for myself. It reads C-like structs from a header file and generates Python classes that mirror them. These classes include all fields from the original struct, and also a few helper functions to make binary conversion easy — turning instances into binary strings and reconstructing them back.

I’ve been using it at work for a while, and I only decided to clean it up and share it after a colleague said it was actually useful for him as well. That pushed me to fix a few bugs and package it in a more usable state.

It is fairly simple to use. For now it only runs on Linux (tested on Ubuntu and Nobara). It is not perfect, but it works well for straightforward struct-based communication.

Workflow / idea behind it

You provide a .hpp file containing C/C++ structs. StructoPy parses these definitions, resolves includes between project headers, and generates corresponding Python classes. Each class contains methods to serialize itself into a binary format and reconstruct itself back from raw bytes.

Internally it relies on generating Python struct format strings (little-endian) and mapping C types directly into binary layouts. It also generates a small test file automatically, which runs basic serialization/deserialization checks to validate correctness of the generated bindings.