Binapy: Binary Data Manipulation
BinaPy is a Python module that simplifies binary data manipulation, offering a fluent interface for encoding, decoding, compressing, decompressing, and hashing data in various formats. It aims to provide a more human-friendly alternative to Python's standard library for these tasks. The library maintains an active release cadence, with version 0.8.0 released in January 2024.
Warnings
- breaking In version 0.3.0, the methods for serialization and parsing were renamed. `serialize_from()` became `serialize_to()`, and `parse_to()` became `parse_from()`.
- gotcha When serializing JSON, `datetime` instances are converted to epoch timestamps. However, there is no automatic conversion back from epoch timestamps to `datetime` objects when parsing JSON.
- gotcha BinaPy objects are subclasses of `bytes`. While this allows seamless integration with functions expecting `bytes`, unexpected behavior might occur if type-checking specifically for `BinaPy` and not `bytes`.
Install
-
pip install binapy
Imports
- BinaPy
from binapy import BinaPy
Quickstart
from binapy import BinaPy
# Encode and compress data fluently
bp = BinaPy("Hello, World!").to("deflate").to("b64u")
print(f"Encoded and compressed: {bp}")
# Decode and decompress back
original_data = bp.decode_from("b64u").decode_from("deflate").ascii()
print(f"Decoded and decompressed: {original_data}")
# BinaPy objects are bytes subclasses
print(f"Is BinaPy instance a bytes object? {isinstance(bp, bytes)}")