kaitaistruct
Kaitai Struct declarative parser generator for binary data: runtime library for Python
What it is and what it does
Kaitai Struct is a declarative approach to binary data parsing. Instead of writing custom code to read and unpack binary structures, you describe the format in a YAML-based .ksy file, compile it with the Kaitai Struct compiler, and use this runtime library to instantiate and navigate the parsed data. The library implements the Kaitai Struct API for Python, providing stream-based access to binary data with automatic field extraction and type handling.
It is language-agnostic—the same .ksy description can be compiled to many target languages—but this package handles only the Python runtime side. You provide the compiled parser class, and the library handles the low-level stream reading. It supports Python 2.7 and Python 3.4 through 3.13, with a single runtime dependency (enum34 for older Python versions).
Use it for:
- Parse custom binary file formats (e.g., image headers, audio metadata) by defining the structure once in .ksy and reusing across languages.
- Decode network packet formats by describing the protocol structure declaratively and letting the runtime extract fields automatically.
- Reverse-engineer or document binary file formats by writing a .ksy description that serves as both specification and working parser.
- Build cross-language tools where the same binary format description compiles to multiple languages, reducing duplication.
- Unpack structured binary data from embedded systems or legacy protocols without manual bit-shifting and byte-order handling.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Kaitai Struct provides a Python runtime library for parsing binary data structures described in a declarative YAML-based format, enabling you to read and unpack binary file formats and network packets without writing custom parsing code.
Yes, if you are already using Kaitai Struct to describe binary formats. The runtime is lightweight, permissively licensed, and actively maintained. Install it only after you have a compiled .ksy parser class ready; the library alone does not parse anything without that upstream compilation step. Not relevant if you are hand-writing binary parsers or using a different declarative format.
Install
kaitaistruct on PyPI
pip
pip install kaitaistructuv
uv add kaitaistructpoetry
poetry add kaitaistructInstalling kaitaistruct
Before you install
Low install friction with a single lightweight dependency (enum34). The package is actively maintained with recent commits, though it has been 340 days since the last release. Supports a wide range of Python versions from 2.7 through 3.13.
License in practice
MIT license is permissive, allowing free use, modification, and distribution with minimal restrictions—suitable for both open-source and commercial projects.
Quickstart
pip install kaitaistruct
from kaitaistruct import KaitaiStream
# Use with a compiled .ksy parser class
with open('file.bin', 'rb') as f:
stream = KaitaiStream(f)
data = YourCompiledParser(stream)
You must first compile a .ksy format description file into a Python parser class using the Kaitai Struct compiler; this library provides only the runtime API, not the compiler itself.
Verify before relying
- Whether the package works with PyPy as claimed in classifiers, or if there are known limitations.
- Current maintenance cadence and likelihood of future releases given the 340-day gap since last release.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — enum34 |
| Maintenance | actively maintained — 340 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 8,459,843/month — #1,621 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: kaitaistruct-0.11-py2.py3-none-any.whl
Keywords: kaitai, struct, construct, ksy, declarative, data structure, data format, file format, packet format, binary, parser, parsing, unpack, development
Tags
More Build Tools packages
Provides reusable utilities for Python…
permissive · top 100 on PyPI
tqdmWraps any iterable to display a real-time…
copyleft · top 100 on PyPI
pippip is the standard installer for Python…
permissive · top 100 on PyPI
hatchlingHatchling is a standards-compliant Python build…
permissive · top 100 on PyPI
grpcio-toolsGenerates Python gRPC service stubs and message…
permissive · top 1,000 on PyPI
pre-commitpre-commit is a framework for installing and…
permissive · top 1,000 on PyPI
constructConstruct is a declarative parser and builder…
permissive · top 5,000 on PyPI
plum-pyTransforms byte sequences into Python objects…
permissive · top 15,000 on PyPI
bitstructPacks and unpacks Python values into bit-level…
permissive · top 5,000 on PyPI
construct-classesParses binary data into Python dataclasses and…
permissive · top 15,000 on PyPI
construct-typingAdds type hints and static type checking…
permissive · top 5,000 on PyPI
msgpackmsgpack serializes and deserializes Python…
permissive · top 1,000 on PyPI
dissect.cstructParse binary data using C-like structure…
permissive · top 15,000 on PyPI
cbitstructA C-accelerated implementation of the bitstruct…
copyleft · top 15,000 on PyPI
pycstructConverts binary data to and from Python…
permissive · top 15,000 on PyPI
polyfile-weaveIdentifies and maps the semantic and syntactic…
permissive · top 5,000 on PyPI