🐍 ProtocolDataUnits: A Python Package

Jay Patel

May 19, 2025

ProtocolDataUnits: A Python Package for Encoding/Decoding Protocol Data Units

ProtocolDataUnits is a lightweight Python package designed to simplify encoding and decoding of binary messages defined by Protocol Data Units (PDUs) — especially in embedded, network, and robotics applications.

It was inspired by the robust features of the ProtocolDataUnits.jl Julia package written by Dr Mandar Chitre and has been reimagined for Python with additional flexibility and compatibility.


✨ Features


🔧 Installation

pip install ProtocolDataUnits

📦 Example Usage

Here is an example to define and use a PDU schema:

from protocoldataunits import encode_pdu, decode_pdu

schema = {
    'type': 'pdu',
    'fields': [
        {'name': 'version', 'type': 'uint', 'size': 4},
        {'name': 'msg_type', 'type': 'uint', 'size': 4},
        {'name': 'length', 'type': 'uint', 'size': 8},
        {'name': 'payload', 'type': 'bytes', 'size': 3},
    ]
}

data = {
    'version': 1,
    'msg_type': 2,
    'length': 3,
    'payload': b'abc'
}

binary = encode_pdu(schema, data)
decoded = decode_pdu(schema, binary)
print(decoded)

🧠 Use Cases


If you’re interested in contributing or need support for your own PDU design, feel free to open an issue or feature request.


📌 Notes

Python Binary Protocol PDU Communication Encoding/Decoding
Jay Patel

Jay Patel

OFI Postdoctoral Fellow in Underwater Communication Systems

My research interests include electronics & communications, distributed underwater robotics, mobile computing and programmable matter.