struct

Stdlib — DataPython 2.0+Advanced

Pack and unpack binary data (C-style structs) to/from bytes

Quick Info

Documentation
Official Docs
Python Version
2.0+
Dependencies
None — Python Standard Library
Install
Included with Python

Learn by Difficulty

Quick Example

python
import struct

# Pack data into bytes
packed = struct.pack("iif", 1, 2, 3.14)
print(f"Packed: {packed}")

# Unpack bytes into values
values = struct.unpack("iif", packed)
print(f"Unpacked: {values}")

The struct module is part of Python's standard library. Pack and unpack binary data (C-style structs) to/from bytes.

Try in Playground

Tags

stdlibdata-structure