Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pabo

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pabo

"Binary parsing for dummies!"

  • 0.1.3
  • PyPI
  • Socket score

Maintainers
1
pabo: Binary parsing for dummies!


Doc Coverage

License Stars

Gitmoji Code style: black

What is this?

Parsing binary data from Python has always been a bit of a pain, thanks to the weirdly designed struct module in Python's standard library. struct uses format strings to specify the layout of binary data, where each character specifies the type of data being packed/unpacked. But no can remember the format characters to begin with! This has led to numerous packages cropping in an attempt to solve the problem, such as:

and many others. pabo is my response to such packages. It makes parsing binary data so easy, anyone could do it! For example, here is how you would parse the beginning of a PNG file to get the width and height of the image:

import pabo as pb

png = pb.Spec(
    {
        "magic": pb.Const(
            b"\x89PNG\x0d\x0a\x1a\x0a",
            pb.Bytes(8),
        ),
        "ihdr_size": pb.Int(4, endian="big"),
        "ihdr_id": pb.Const(b"IHDR", pb.Bytes(4)),
        "width": pb.Int(4, endian="big"),
        "height": pb.Int(4, endian="big"),
    }
)

data = png.parse("example.png")

which would return a dictionary with the parsed data, like so:

{
     'magic': b'\x89PNG\r\n\x1a\n',
     'ihdr_size': 13,
     'ihdr_id': b'IHDR',
     'width': 602,
     'height': 172,
}

For more real examples, check out the priwo package, which uses pabo to parse pulsar data from binary files (in fact, many of pabo's features are directly motivated by their need in priwo!). Documentation is in development, so stay tuned!

Installation

Installing pabo is as easy as:

pip install pabo

Philosophy

The philosophy behind pabo is: be simple, yet be fast and full of features. This implies that I deliberately avoid coding in features that are too magical or obscure, in contrast to other packages, such as construct. This allows users of pabo to also become contributors, since the internals of pabo are clean and easy-to-understand.

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc