Binal
Declarative, type-safe binary modeling for Python.
Binal is a pure-Python library for defining, encoding, decoding, validating, and composing binary data structures using native Python classes and type annotations.
It provides a unified binary modeling system that eliminates repetitive serialization logic, manual buffer management, offset calculations, bitwise operations, and structural validation.
The data model serves as the single source of truth for both Python objects and their binary representations.
Installation
Requires Python 3.11+.
uv add binal
pip install binal
Quick Start
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'
packet = Packet.decode(data)
# Packet(version=1, payload=b'Hello')
Features
- Declarative models with native type annotations
- Integers (including custom widths), floats, booleans, bytes, strings, and bit fields
- Nested models, collections, enums, and tagged unions
- Length-prefixed, fixed-length, null-terminated, and length-dependent fields
- Derived lengths, counts, and checksums (CRC32, CRC16, Adler32)
- Conditional and dependent fields
- Variable-length integers: ULEB128, SLEB128, ZigZag
- Schema introspection with field offsets and sizes
- File, buffer, stream, and asynchronous I/O
- Structured errors with field paths and byte offsets
- Zero runtime dependencies, pure Python
See the documentation and examples/ for more.
Development
uv sync --locked
uv run ruff format
uv run ruff check
uv run pyright
uv run pytest
uv run pytest --cov=binal
uv build
License
MIT. See LICENSE.
Metadata
Release files for binal 0.1.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.1.1.tar.gz | 20.4 kB | With provenance | Details for binal-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| binal-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for binal-0.1.1-py3-none-any.whl |
Total release size: 46.6 kB
Release files / binal-0.1.1.tar.gz
| Download URL | binal-0.1.1.tar.gz |
|---|---|
| Size | 20.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0dfadcb83e9032e54aa06cb2d5246fe869a0abc42de2f6cb32a6a3b9b8789717
|
|
BLAKE2b-256 checksum How to use checksums |
08262a534e7cb658421ba5717f10d61c9ec9cf653d16a1c0b1ba0ea1baa4d8e6
|
| 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 25, 2026.
Transparency logRelease files / binal-0.1.1-py3-none-any.whl
| Download URL | binal-0.1.1-py3-none-any.whl |
|---|---|
| Size | 26.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
999274c719a068c13b70eb9116f62d56de783cbae8e636ca011e81cf48824ec0
|
|
BLAKE2b-256 checksum How to use checksums |
f5a49b46d5b41a01ae7bcc399b4dd7e74527e00711694b454795c37f6f604cdc
|
| 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 25, 2026.
Transparency logSecurity for binal 0.1.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
Both files in this release have been uploaded with provenance metadata.
Attestation for binal-0.1.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 25, 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.