Binal
Declarative, type-safe binary modeling for Python.
Install
binal supports Python 3.12 and newer, with zero runtime dependencies. Add it to a uv project:
uv add binal To install it in an active Python environment:
pip install binal Build from source
Run these commands from the repository root with uv and Python 3.12 or newer.
uv sync --locked Encode a packet
from typing import Annotated
from binal import BinaryModel, Prefixed, UInt8, UInt16
class Packet(BinaryModel, byte_order="big"):
version: UInt8
payload: Annotated[bytes, Prefixed(UInt16)]
packet = Packet(version=1, payload=b"Hello")
data = packet.encode() # b"\x01\x00\x05Hello"
print(Packet.decode(data))