bytespec

Describe data with a Python class, save it as bytes, and read it back. bytespec determines where each field ends and the next begins.

from bytespec import ProtoModel

class User(ProtoModel):
    name: str
    active: bool

user = User(name="Anna", active=True)
encoded = user.encode()
decoded = User.decode(encoded)

print(decoded.name, decoded.active)
assert decoded == user
Anna True

This is a new User with the same values. Lists and nested models can also be written as bytes. For an existing binary format, explicitly choose field sizes and order, without a separate schema language or code generation.

pip install bytespec

or

uv add bytespec

Python 3.10+. Start with your first model or choose a task:

Getting started

From a Python class to a breakdown of the resulting bytes. No protocol knowledge required.

Your first model
Why bytespec?

One packet in bytespec, struct, and Construct. When each tool fits.

Why bytespec?
Recipes

Read a TCP packet, parse multiple messages, or configure byte order.

Recipes
API reference

Signatures, parameters, and precise reading and writing rules.

API Reference