skillfed

pycstruct

Binary data handling in Python using dictionaries

pycstruct v0.12.2 164.4K downloads/30d#10,549 on PyPI26
Permissive license MIT DORMANT released

What it is and what it does

pycstruct is a Python library for bidirectional conversion between binary data and Python dictionaries or objects. It lets you define binary layouts using a C-struct-like syntax—specifying fields with types like uint32, float32, bool8, and arrays—then serialize Python data into binary form or deserialize binary files back into Python objects. The library handles complex nested structures, unions, bitfields, and enums, with full control over byte order and field alignment.

Typical use cases are reading and writing binary file formats or parsing binary protocols transmitted over networks. The package also includes a C source code parser that can automatically generate pycstruct definitions from existing C struct declarations, eliminating manual definition work when you already have C headers.

Use it for:

  • Parse binary file formats (e.g., image headers, audio metadata) by defining the layout once and deserializing file contents into dictionaries
  • Serialize Python objects into binary protocol messages for network transmission with precise byte-order and alignment control
  • Automatically generate pycstruct definitions from C source code to avoid manual transcription of struct layouts
  • Handle embedded C structs, unions, and bitfields in Python without writing custom pack/unpack logic
  • Read and write binary data with variable-length arrays and nested structures at any nesting depth

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Converts binary data to and from Python dictionaries or objects using C-struct-like definitions, supporting structs, unions, bitfields, enums, and arrays with configurable byte order and alignment.

Yes, if you need to work with binary data or C-compatible struct layouts. The package is stable, has no dependencies, and carries permissive MIT licensing. However, dormant maintenance (873 days since last release) means you should verify it handles your specific use case before committing to it in production—no active support or bug fixes should be expected.

Install

pycstruct on PyPI

pip

pip install pycstruct

uv

uv add pycstruct

poetry

poetry add pycstruct

Installing pycstruct

Before you install

Low install friction with no runtime dependencies. Dormant maintenance status—last release was 873 days ago, though the repository remains active with a recent commit on 2024-03-24.

License in practice

MIT license permits commercial and private use with minimal restrictions, requiring only attribution and inclusion of the license notice.

Quickstart

import pycstruct

person = pycstruct.StructDef()
person.add('utf-8', 'name', length=50)
person.add('uint32', 'age')
person.add('float32', 'height')

with open('data.bin', 'rb') as f:
    result = person.deserialize(f.read())

Verify before relying

  • Whether the package is actively maintained or if dormant status signals abandonment risk
  • Compatibility with Python versions beyond 3.11 (classifiers list 3.4–3.11 but no explicit upper bound)

Package facts

License MIT (permissive)
Python support not specified
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance dormant — 873 days since the last release
Last repo commit
First released
Downloads 164,380/month — #10,549 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: pycstruct-0.12.2-py3-none-any.whl

Keywords: struct, enum, bitfield, binary, protocol, dict, dictionary

Development Status :: 3 - AlphaIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.4Programming Language :: Python :: 3.5Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software Development :: Build Tools

Tags

binary data serializationC struct to Pythonbinary protocol parsingstruct deserializationbinary file handlingnetwork protocol databitfield parsing
binary-serializationc-interop

More Build Tools packages