Skip to main content

A beginner-friendly binary format packing/unpacking module with full hex and byte control.

Project description

binformatlib

Version: 6.1.0
Author: jony eldry
License: MIT

binformatlib is a lightweight and beginner-friendly Python library for packing and unpacking binary files with full control over bytes and hexadecimal representations. It supports recursive nested field structures, custom EOF markers, and encodes the full file as hex for maximum readability and integrity.


✨ Features

  • Convert values (strings, integers, bytes, lists, etc.) into binary-safe formats
  • Pack structured data dictionaries into hex-encoded binary files
  • Unpack hex-encoded binary files back into nested Python dictionaries
  • Flat field key formatting using dot notation (e.g., header.version)
  • Optional custom EOF marker
  • Simple to use and extend

📦 Installation

You can install binformatlib via pip:

pip install binformatlib

🚀 Quick Start

Packing a File

from binformatlib import pack

format = {
    "meta": {
        "version": 1,
        "author": "jony"
    },
    "data": None,
    "end of file": "<EOF>"
}

pack(format, "output.bin", "Hello, World!")

Unpacking a File

from binformatlib import unpack

data = unpack("output.bin")
print(data)

🔧 Internals

_to_bytes(value)

Converts input of type str, int, bytes, list, or None into a bytes object.

_flatten_fields(dict, prefix='')

Recursively flattens nested dictionaries into key-value pairs using dot notation.

pack(format: dict, output_file: str, data: str) -> bool

Serializes and hex-encodes a structured dictionary with data into a .bin file.

unpack(input_file: str) -> dict

Reconstructs the original nested dictionary from a packed .bin file.

tohex(value)

Converts a string to its hexadecimal representation.

fromhex(hex_string: bytes)

Converts a hexadecimal-encoded bytestring back to raw bytes.


🧪 Example

$ python binformatlib.py
{'data': b'test'}

📁 File Format

Each line in the binary file follows the format:

key=hexvalue

Where key can use dot-notation (e.g., meta.version) and hexvalue is the hex string of the binary-encoded data.


🛠 Development

Clone and run locally:

git clone https://github.com/yourusername/binformatlib.git
cd binformatlib
python binformatlib.py

📄 License

This project is licensed under the MIT License.


✉️ Contact

Author: jony eldry
Email: umayashinderu@gmail.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

binformatlib-6.2.0.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

binformatlib-6.2.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file binformatlib-6.2.0.tar.gz.

File metadata

  • Download URL: binformatlib-6.2.0.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for binformatlib-6.2.0.tar.gz
Algorithm Hash digest
SHA256 08ed5e0cc5cf9abf2d50bceae6add361adfa4847c4ccf094d096da51328abc9e
MD5 39104d10039b4c77b747fb7346613470
BLAKE2b-256 698a96f77a032c8ec35cea04a167c5afd5fdf250fd9b236aaa1646d412a54601

See more details on using hashes here.

File details

Details for the file binformatlib-6.2.0-py3-none-any.whl.

File metadata

  • Download URL: binformatlib-6.2.0-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for binformatlib-6.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ece7c11f19f89fa6a576a04fc5eb926de0cbad5ca619455a6b3c3c4961cb299d
MD5 798eec04b4100c7b0dbfd074e66ffdfd
BLAKE2b-256 026179ed26d103692071cc11505702cf46360393334bf13f478b2bbaf63064ba

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page