Skip to main content

binal

Declarative binary modeling for Python

Define a binary format once, as a Python class, and get encoding,
decoding, validation, and layout from the same declaration.

PyPI version Python 3.13+ License: MIT

Documentation · Capabilities · Installation · Usage · Contributing


Capabilities

Area What it covers
Binary types Integers of any width up to 128 bits, varints (LEB128, zigzag, VLQ), binary floats from 8-bit to binary128, decimal floats (BID and DPD), fixed point, BCD, bytes, and strings (sized, prefixed, terminated, greedy)
Semantic types UUIDs, IP and MAC addresses, timestamps, dates, times, durations, complex and rational numbers
Modeling Nested and recursive models, bit fields, lists, tuples, enums and flags, tagged and untagged unions, conditional and dependent fields, derived lengths and counts
References Offsets and pointers into address spaces, shared and cyclic objects
Checksums CRC-8, CRC-16, CRC-32, CRC-32C, CRC-64, and Adler-32, verified on decode
I/O File, buffer, stream, and asynchronous I/O, incremental parsing and partial decoding, sequences of records in one call
Validation Field constraints, cross-field validation, and structured errors with field paths and byte offsets
Introspection Static schema and runtime layout with field offsets and sizes
Formats and documents .binal schemas run from Python, lossless editing that keeps unknown bytes, and schemas for real formats (ELF, ZIP, PCAPNG, TIFF, MP4, SQLite, PNG, GIF, WAV, tar, gzip)
Portable schemas A model's format exported as JSON for other languages and tools
Low-level I/O BinaryReader and BinaryWriter for ad-hoc formats and custom codecs

Installation

binal supports Python 3.13 and newer. It depends on fastcrc (CRC checksums) and tibs (bfloat16 and 8-bit floats), both with prebuilt wheels.

Add it to a uv project:

uv add binal

To install it in an active Python environment:

pip install binal

To build from source, which needs Rust 1.88 or newer:

git clone https://github.com/nolantw/binal
cd binal
uv sync --locked

Usage

from io import BytesIO
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"
assert Packet.decode(data) == packet

# Several records in one stream, read one at a time.
records = list(Packet.iter_read(BytesIO(data + data)))

# Records stored back to back, in one call.
assert Packet.decode_many(Packet.encode_many([packet, packet])) == [packet, packet]

# One record at an offset, with the bytes it consumed.
record, consumed = Packet.decode_partial(data + b"trailing")

# Where each field landed in the encoding.
print(packet.layout().total_bytes)  # 8

Project status

binal is pre-1.0: the API may change between minor releases.

License

MIT. See LICENSE.

Metadata

Release files for binal 0.6.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 binal 0.6.0
File Size Uploaded Provenance Actions
binal-0.6.0.tar.gz 258.3 kB With provenance Details for binal-0.6.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for binal 0.6.0
File Actions
binal-0.6.0-cp313-abi3-win_amd64.whl CPython 3.13 abi3 Windows x86-64 Details for binal-0.6.0-cp313-abi3-win_amd64.whl
binal-0.6.0-cp313-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.13 abi3 Linux glibc 2.17+ x86-64 Details for binal-0.6.0-cp313-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
binal-0.6.0-cp313-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.13 abi3 Linux glibc 2.17+ ARM64 Details for binal-0.6.0-cp313-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
binal-0.6.0-cp313-abi3-macosx_11_0_arm64.whl CPython 3.13 abi3 macOS 11.0+ ARM64 Details for binal-0.6.0-cp313-abi3-macosx_11_0_arm64.whl
binal-0.6.0-cp313-abi3-macosx_10_12_x86_64.whl CPython 3.13 abi3 macOS 10.12+ x86-64 Details for binal-0.6.0-cp313-abi3-macosx_10_12_x86_64.whl

Total release size: 5.4 MB

Release files / binal-0.6.0.tar.gz

Download URL binal-0.6.0.tar.gz
Size 258.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f2c3f0a299204f3f818d260568759f9fb710afe806736e43be23ca5c902207f0
BLAKE2b-256 checksum
How to use checksums
25cae251df7540df0b63582ac2ec80d3f1cbf8dcbacdee1c173711a07258f0eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 29, 2026.

Transparency log

Release files / binal-0.6.0-cp313-abi3-win_amd64.whl

Download URL binal-0.6.0-cp313-abi3-win_amd64.whl
Size 955.7 kB
Tags CPython 3.13 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
c17e74b7db30ff4c7f64d53d1a801d4ea64ac1b480ff4fdd333645ad6b3babe0
BLAKE2b-256 checksum
How to use checksums
966d50cbe20cacc533b472ba98457eeaa6523a0cbfafe8d40a028c9a9a0dc2ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 29, 2026.

Transparency log

Release files / binal-0.6.0-cp313-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL binal-0.6.0-cp313-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.1 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
727156212eebc86eddb4b37698627082a31b4f59e92717675f158ad7e95ae919
BLAKE2b-256 checksum
How to use checksums
3906adc22be553352c4f62f60deb22594e9ecb8d133388935d36b8519c102194
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 29, 2026.

Transparency log

Release files / binal-0.6.0-cp313-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL binal-0.6.0-cp313-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 1.1 MB
Tags CPython 3.13 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
e0a1449e026fe83a0c09e0903b0fe2edf997b088db420004d3612338f73d6fbc
BLAKE2b-256 checksum
How to use checksums
6e63cc813cf1696233487ce9de24ebf823ee616ec4621007e3191f9e2f3053e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 29, 2026.

Transparency log

Release files / binal-0.6.0-cp313-abi3-macosx_11_0_arm64.whl

Download URL binal-0.6.0-cp313-abi3-macosx_11_0_arm64.whl
Size 1.0 MB
Tags CPython 3.13 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
eaba5aba7c61a1c107cdececa3f2a7bb3c73178d8a17e3f1c8ff1c7916172ec5
BLAKE2b-256 checksum
How to use checksums
be5614e427dfa4cf0a166e8aa6c646c1e1d56d9f1165fdb8d3602664ce45bf7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 29, 2026.

Transparency log

Release files / binal-0.6.0-cp313-abi3-macosx_10_12_x86_64.whl

Download URL binal-0.6.0-cp313-abi3-macosx_10_12_x86_64.whl
Size 1.0 MB
Tags CPython 3.13 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
80fb28ac93163e8eb0f95809585fe6f70b2125bfca39af4117e29397c5146501
BLAKE2b-256 checksum
How to use checksums
13dc5e2609c663570757056902981a1b0d02cbacaa1b0ae872b9da4c33d1a765
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 29, 2026.

Transparency log

Security for binal 0.6.0

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.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for binal-0.6.0.tar.gz

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 Nov 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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