Skip to main content

bytespec

English · Русский

Typed Python models over an explicit sequential binary representation. One model reads and writes numbers, strings, lists, and nested objects; you choose their representation, and the library tracks lengths and offsets.

from bytespec import Constructor, PayloadLength, ProtoModel, field
from bytespec.types import UInt32


class User(ProtoModel):
    __constructor__ = 0x12
    __header__ = (Constructor(1), PayloadLength(1))

    id: UInt32
    name: str = field(prefix_length=1)


user = User(id=42, name="Anna")
data = user.encode()
restored = User.decode(data)

print(data.hex(" "))  # 12 09 00 00 00 2a 04 41 6e 6e 61
print(restored.name)  # Anna
assert restored == user

12 identifies the message; 09 is the computed length of its fields. Next come the four-byte id and a UTF-8 name with a one-byte length prefix. In your application, these are ordinary int and str values. Your first models can use the default framing without setting __header__; for an existing format, you can customize or remove it.

bytespec fits custom or existing sequential binary protocols when you want to work with classes without a separate schema language or code generation. It supports optional fields through flags, IntEnum, UUID, datetime, numeric encodings, and custom codecs. This is a small 0.1.0 library: for a flexible binary parser DSL, consider Construct; for standard JSON/MessagePack, msgspec; for a schema ecosystem with its own wire format, protobuf.

Installation

Python 3.10+:

pip install bytespec

Or uv add bytespec.

Documentation

The full guide and API reference are available in Russian and English. To build both versions from a checkout:

uv sync --locked --group docs
uv run --no-sync python -m sphinx -E -a -n -W --keep-going -b html -D language=ru docs docs/_build/html/ru
uv run --no-sync python -m sphinx -E -a -n -W --keep-going -b html -D language=en docs docs/_build/html/en

Open docs/_build/html/en/index.html. The language switcher keeps you on the same page. Start with Getting started, Why bytespec?, or Headers and framing, then consult the API reference. The documentation sources and build instructions are in Russian; Sphinx applies the English translation catalogs when building the English version.

Take a known packet from your protocol, describe a few fields, and compare the re-encoded result with the original bytes. That is a useful first check of whether the library fits your format.

MIT license.

Release files for bytespec 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bytespec 0.1.0
File Size Uploaded
bytespec-0.1.0.tar.gz 19.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bytespec 0.1.0
File Interpreter ABI Platform
bytespec-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 50.8 kB

Release files / bytespec-0.1.0.tar.gz

Download URL bytespec-0.1.0.tar.gz
Size 19.2 kB
Tags Source
SHA-256 checksum
How to use checksums
85899a4918586a3fb71e5ed4833d09e1447d03962ecb9803bbdc54003440e156
BLAKE2b-256 checksum
How to use checksums
f19cce13bcf181459fdd952a1fd6b6ed66a4ffd389a80f5811b9fc29669f535f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 13, 2026.

Transparency log

Release files / bytespec-0.1.0-py3-none-any.whl

Download URL bytespec-0.1.0-py3-none-any.whl
Size 31.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8f3e6af58cc80e940c02c61f40de0a52c359ae2bd1beb5440c0a98f711147bf4
BLAKE2b-256 checksum
How to use checksums
ee11dd3620ae4a28446c05e229150b4f5112766ab200417671a6e8178dd963f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 13, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page