Skip to main content

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.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.1.0
File Size Uploaded Provenance Actions
binal-0.1.0.tar.gz 20.4 kB With provenance Details for binal-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 46.6 kB

Release files / binal-0.1.0.tar.gz

Download URL binal-0.1.0.tar.gz
Size 20.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4384e0ac14e04fff09965e7eb9259a792ea046b62164786471be5ff0d693626a
BLAKE2b-256 checksum
How to use checksums
414c6cdbf3d9adc536542666c79165625bd3856ba1f1eb1fb13903549fa7afc9
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 log

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

Download URL binal-0.1.0-py3-none-any.whl
Size 26.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
81685c01b69e3fc0ffd243e0a54d99598bcf081412809552493fa2d759362e42
BLAKE2b-256 checksum
How to use checksums
c4bb74563cabfe96edbb6ae028f053fe83fe403c10fd46f9fa96bbd39febf65b
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 log

Security for binal 0.1.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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for binal-0.1.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 25, 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