A beginner-friendly binary format packing/unpacking module with full hex and byte control.
Project description
binformatlib
Version: 6.3.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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file binformatlib-6.3.0.tar.gz.
File metadata
- Download URL: binformatlib-6.3.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b0a4121d6d80442be111180cdd66825708c81e5af2211827cfdd2be2e92fe18
|
|
| MD5 |
9cde64d1e4d343362cc51c0d1c12d66f
|
|
| BLAKE2b-256 |
5ed96fcbc3fd0fb4318e11621da324f71c249435c7533f229a593a63ef2959c2
|
File details
Details for the file binformatlib-6.3.0-py3-none-any.whl.
File metadata
- Download URL: binformatlib-6.3.0-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30fcaef586aca89ce3a209a4d4e1415fee8def0b3d7a51a424f6057d61fb47c1
|
|
| MD5 |
951f276c4b07b5328b19fd21662719fb
|
|
| BLAKE2b-256 |
bf563cde7cdf18901436643a64fc227914de9f61060453f280524fef34f467f8
|