dissect.cstruct
A Dissect module implementing a parser for C-like structures: structure parsing in Python made easy
What it is and what it does
dissect.cstruct is a binary structure parser that lets you define C-like structures in a simple text format and use them to parse raw binary data into Python objects. It handles common C constructs—basic types, arrays, enums, unions, nested structures, and bit fields—with minimal syntax overhead. You write a structure definition, load it into a parser instance, then call the resulting structure class on binary data (bytes or file-like objects) to get back a Python object with typed fields that you can read, modify, and serialize back to bytes.
The library is designed for simplicity: no complex syntax, filters, or preprocessing—just straightforward structure parsing. It's particularly useful for reverse-engineering binary file formats, parsing kernel data structures, or handling custom binary protocols where you can reuse structure definitions from existing C codebases with little or no modification. It compiles structures to optimized Python classes by default for better performance.
Use it for:
- Parse EXT4 superblocks or other kernel data structures by copying C definitions from Linux source.
- Reverse-engineer custom binary file formats by defining their layout and parsing samples.
- Handle binary network protocols or file formats where you need bidirectional serialization.
- Parse forensic or log data with fixed binary layouts in incident response workflows.
- Work with embedded device data or firmware images with known C struct definitions.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Parse binary data using C-like structure definitions, converting raw bytes into typed Python objects and back again.
Yes. Zero dependencies, active maintenance, stable API, and Apache-2.0 licensing make it a low-risk choice. Install if you need to parse binary data with C-like structures; the straightforward syntax and ability to reuse real C definitions from open-source projects make it significantly more practical than manual struct.unpack() calls for complex formats.
Install
dissect-cstruct on PyPI
pip
pip install dissect-cstructuv
uv add dissect-cstructpoetry
poetry add dissect-cstructInstalling dissect.cstruct
Before you install
Low install friction with no runtime dependencies. Active maintenance since 2018, last commit 2026-08-10, and marked Production/Stable.
License in practice
Apache-2.0 permissive license allows commercial and private use with minimal restrictions.
Quickstart
from dissect.cstruct import cstruct
parser = cstruct().load("""
struct example {
uint8 a;
char b[5];
};
""")
data = b"\x01hello"
result = parser.example(data)
print(result.a, result.b)
Requires Python 3.10 or later.
Verify before relying
- Whether compiled structures (the default) provide measurable performance gains for typical workloads.
- Compatibility with structure definitions from specific C projects or standards beyond the Linux kernel example given.
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 267 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 227,946/month — #9,162 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: dissect_cstruct-4.7-py3-none-any.whl
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
dissect.ntfsParses and reads NTFS file systems, the primary…
agpl · top 15,000 on PyPI
pycstructConverts binary data to and from Python…
permissive · top 15,000 on PyPI
bitstructPacks and unpacks Python values into bit-level…
permissive · top 5,000 on PyPI
dissect.hypervisorParses hypervisor disk, backup, and…
agpl · top 15,000 on PyPI
dissect.volumeParses disk volume and partition systems…
agpl · top 15,000 on PyPI
dissect.targetdissect.target provides a unified API and…
agpl · top 15,000 on PyPI
construct-classesParses binary data into Python dataclasses and…
permissive · top 15,000 on PyPI
RoffIORoffio reads and writes Roxar Open File Format…
copyleft · top 15,000 on PyPI
cbitstructA C-accelerated implementation of the bitstruct…
copyleft · top 15,000 on PyPI
pymp4Parses and builds MP4 box structures from…
permissive · top 5,000 on PyPI