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.
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.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| binal-0.6.1.tar.gz | 258.9 kB | With provenance | Details for binal-0.6.1.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| binal-0.6.1-cp313-abi3-win_amd64.whl | CPython 3.13 | abi3 | Windows x86-64 | Details for binal-0.6.1-cp313-abi3-win_amd64.whl |
| binal-0.6.1-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.1-cp313-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
| binal-0.6.1-cp313-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl | CPython 3.13 | abi3 | Linux glibc 2.17+ ARM64 | Details for binal-0.6.1-cp313-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
| binal-0.6.1-cp313-abi3-macosx_11_0_arm64.whl | CPython 3.13 | abi3 | macOS 11.0+ ARM64 | Details for binal-0.6.1-cp313-abi3-macosx_11_0_arm64.whl |
| binal-0.6.1-cp313-abi3-macosx_10_12_x86_64.whl | CPython 3.13 | abi3 | macOS 10.12+ x86-64 | Details for binal-0.6.1-cp313-abi3-macosx_10_12_x86_64.whl |
Total release size: 5.5 MB
Release files / binal-0.6.1.tar.gz
| Download URL | binal-0.6.1.tar.gz |
|---|---|
| Size | 258.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
177ad751b936b64bdd6c15f31266d039cb839306a06d69f976b961091c783787
|
|
BLAKE2b-256 checksum How to use checksums |
5409afbaccb2adb15adfd93ecfdd10f314fe0d4c442543bd7229a5d5436ed317
|
| 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 30, 2026.
Transparency logRelease files / binal-0.6.1-cp313-abi3-win_amd64.whl
| Download URL | binal-0.6.1-cp313-abi3-win_amd64.whl |
|---|---|
| Size | 959.9 kB |
| Tags | CPython 3.13 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
37cda26ecefd1b2cda28a1e1274a9a833f3122cc0fea43ed6e9c6b93b188a4d0
|
|
BLAKE2b-256 checksum How to use checksums |
b1daf8846ade21a688cc662f90d21beb41fe54ede71627a3029cbe20241e81fe
|
| 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 30, 2026.
Transparency logRelease files / binal-0.6.1-cp313-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | binal-0.6.1-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 |
446c006b60998f531e4fd28bc4e645f1468492a5f43892e51ff1929e97031154
|
|
BLAKE2b-256 checksum How to use checksums |
478daf0598ba60e86f49c5aeee7eb1862f9f7873cbf01e305a38acadfb614237
|
| 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 30, 2026.
Transparency logRelease files / binal-0.6.1-cp313-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
| Download URL | binal-0.6.1-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 |
8baf5a83fbf9bb3b6d82f6da4c9442f83be34ef7fd1f200750c7fcbf35acc8f9
|
|
BLAKE2b-256 checksum How to use checksums |
66744f5915f226b9d4055d31ca50e65b0a0cca07deaaa44f60576ce8c025a40c
|
| 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 30, 2026.
Transparency logRelease files / binal-0.6.1-cp313-abi3-macosx_11_0_arm64.whl
| Download URL | binal-0.6.1-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 |
72b9206a86414304fe7835e3c1129f0ae26dc8d22765a221ff4a450977769d66
|
|
BLAKE2b-256 checksum How to use checksums |
5f871bead6e0f69f1dee41c608000f891fd69bbab4a7c06e4a61ee0c5377b18b
|
| 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 30, 2026.
Transparency logRelease files / binal-0.6.1-cp313-abi3-macosx_10_12_x86_64.whl
| Download URL | binal-0.6.1-cp313-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.13 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
a0d1d65e83b52a70063e0064a221623d6d68c560bdff97410e935811b9348d67
|
|
BLAKE2b-256 checksum How to use checksums |
c7ebac08d766e8508ee87dbf94770e49073044e4b85911b691ecb57722b72dcb
|
| 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 30, 2026.
Transparency logSecurity for binal 0.6.1
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.
Attestation for binal-0.6.1.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 30, 2026.
Transparency logA 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.