Skip to content

MatrixEditor/caterpillar

Repository files navigation

Caterpillar - 🐛

python Build and Deploy Docs Run Tests GitHub issues GitHub License

Warning

This project is still in beta/testing phase. Expect bugs, naming changes and errors while using this library. C API Reference is WIP, C extensions are supported since v2.1.0.

Caterpillar is a Python 3.12+ library to pack and unpack structurized binary data. It enhances the capabilities of Python Struct by enabling direct class declaration. More information about the different configuration options will be added in the future. Documentation is here >.

Caterpillar is able to:

  • Pack and unpack data just from processing Python class definitions (including support for bitfields, c++-like templates and c-like unions!),
  • apply a wide range of data types (with endianess and architecture configuration),
  • dynamically adapt structs based on their inheritance layout,
  • reduce the used memory space using __slots__,
  • allowing you to place conditional statements into class definitions,
  • insert proper types into the class definition to support documentation and
  • it helps you to create cleaner and more compact code.
  • You can even extend Caterpillar and write your parsing logic in C or C++!!

Installation

Note

As of Caterpillar v2.1.2 it is possible to install the library without the need of compiling the C extension.

Simply use pip to install the package with all tools, all extra packages and the C extension:

pip install "caterpillar[all]@git+https://github.com/MatrixEditor/caterpillar.git"

Note

You will need to install make, a C compiler and the Python3.12 development package.

If you just want to use the Python package without any native modules written in C, you can specify the following environment variables:

  • CP_DISABLE_NATIVE - Disables installation of the native C extension
  • CP_DISABLE_TOOLS - Disables installation of extra tools

For instance, the following command will install the caterpillar package without a native interface and without extra tools:

CP_DISABLE_NATIVE=TRUE \
CP_DISABLE_TOOLS=TRUE \
pip install git+https://github.com/MatrixEditor/caterpillar

Starting Point

Please visit the Documentation, it contains a complete tutorial on how to use this library.

Other Approaches

A list of similar approaches to parsing structured binary data with Python can be taken from below:

The documentation also provides a Comparison to these approaches.

License

Distributed under the GNU General Public License (V3). See License for more information.