Skip to content

dargueta/binobj

Repository files navigation

binobj

Build status Python versions Installs per month Total installs

A cross-platform Python 3 library for reading and writing structured binary data in an object-oriented (ish) style.

Why use binobj?

You may have used Python's built-in struct library to load and dump binary data. It's unwieldy for larger or more complex data structures, and the format strings are easy to get wrong. binobj is different in that it takes a class-based approach to declaring binary structures.

Take a look at this example using struct:

The same example rewritten using binobj:

binobj also has other advantages in that it supports strings in any encoding Python supports, toggling endianness on a per-field basis (necessary for ISO 9660 images), a variety of integer encodings, computed fields, validation, and more.

System Requirements

  • This package will not work on a mixed-endian system. Those are pretty rare nowadays so chances are you won't have a problem.
  • This has been tested on CPython 3.7-3.11, PyPy 3.7-3.9.

Installation

You can install this with pip like so:

  • Be sure to use pip3 and not pip, because pip defaults to Python 2.
  • If you get a "Permission Denied" error, try:

Side note: Don't use sudo (even sudo -EH) to force a package to install, as that's a security risk. See this answer on Stack Overflow to find out why.

Testing and Development

This package uses Tox to run tests on multiple versions of Python.

Setup

To set up your development environment, you'll need to install a few things.

  • For Python version management, I use pyenv-virtualenv. Follow the installation instructions there.
  • You'll also need make. Depending on your platform you can install it in one of several ways:
    • macOS: brew install make
    • Debian systems (e.g. Ubuntu): sudo apt-get install make
    • Windows: Use Cygwin and install it during setup.

Once you have those installed, in the root directory of this repo run:

Running the Tests

To run the unit tests for all supported versions of Python, run make test. The environments will automatically be rebuilt if needed.

Issues and Feature Requests

To report an issue, request a feature, or propose a change, please file a report on the project's GitHub page here.

License

I'm releasing this under the terms of the 3-Clause BSD License. For the full legal text, see LICENSE.txt in the repository.

About

A Python library for reading and writing structured binary data.

Resources

License

Stars

Watchers

Forks

Packages

No packages published