skillfed

kaitaistruct

Kaitai Struct declarative parser generator for binary data: runtime library for Python

kaitaistruct v0.11 8.5M downloads/30d#1,621 on PyPI107
Permissive license MIT Active released

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 kaitaistruct

uv

uv add kaitaistruct

poetry

poetry add kaitaistruct

Installing 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

Development Status :: 4 - BetaIntended Audience :: DevelopersProgramming Language :: Python :: 2Programming Language :: Python :: 2.7Programming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.4Programming Language :: Python :: 3.5Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software Development :: Build Tools

Tags

binary data parserdeclarative binary formatkaitai struct runtimebinary file format parsernetwork packet parsingstructured data unpackingksy format parser
binary-parsingdeclarative-formatcross-language

More Build Tools packages