Registry / serialization / binapy

binapy

JSON →
library0.8.0pypypi✓ verified 22d ago

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.

pip install binapy
INSTALL
IMPORT
SIG · BINAPY
B
binapy
serializationpythonv0.8.0
Install
1.6s avg
Import
72ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.8.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.076s · 18.3MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.068s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

BinaPy
from binapy import BinaPy

Initialize a BinaPy object with string or bytes data, then chain method calls for transformations like compression (deflate) and encoding (base64url). The object can then be decoded back in reverse order of operations. BinaPy instances are subclasses of `bytes`.

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)}")
Debug
Known issues
breakingIn version 0.3.0, the methods for serialization and parsing were renamed. `serialize_from()` became `serialize_to()`, and `parse_to()` became `parse_from()`.
fix
Update method calls from `serialize_from()` to `serialize_to()` and `parse_to()` to `parse_from()`.
affects: >=0.3.0
gotchaWhen 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.
fix
Manually convert epoch timestamps back to `datetime` objects after parsing JSON data if `datetime` instances are expected.
affects: >=0.2.0
gotchaBinaPy 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`.
fix
Be aware that `isinstance(binapy_obj, bytes)` will return `True`. If strict type distinction is required, consider explicit checks or conversions.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'binapy'
The 'binapy' package is not installed in your Python environment, or the Python interpreter cannot find it.
fix
Install the binapy library using pip: `pip install binapy`
ImportError: cannot import name 'BinaPy' from 'binapy'
You are trying to import 'BinaPy' from the 'binapy' package, but the class name is case-sensitive, or you might be trying to import 'binapy' (the module) as a class.
fix
Ensure you are importing the `BinaPy` class with correct capitalization: `from binapy import BinaPy`
ValueError: Unsupported format: 'unsupported_format'
You are attempting to encode or decode data using a format string ('unsupported_format') that BinaPy does not recognize or support. BinaPy supports formats like 'base64', 'hex', 'gzip', 'deflate', etc..
fix
Use a supported encoding, decoding, or compression format string. For example, to encode to base64: `bp.to('base64')` or decode from hex: `bp.decode_from('hex')`
zlib.error: Error -3 while decompressing data: incorrect header check
You are attempting to decompress data that was not compressed with the expected algorithm (e.g., gzip or deflate) or the data is corrupted.
fix
Ensure the data being passed to a decompression method (like `.decode_from('gzip')` or `.decode_from('deflate')`) was originally compressed using that specific algorithm and is not corrupted.
UnicodeDecodeError: 'ascii' codec can't decode byte 0x... in position ...: ordinal not in range(128)
You are trying to interpret binary data (a `BinaPy` object, which is a `bytes` subclass) as an ASCII string, but it contains non-ASCII characters, typically when calling `.ascii()` on data that hasn't been decoded from its original encoding.
fix
Before calling `.ascii()`, ensure the `BinaPy` object has been decoded from its original character encoding (e.g., 'utf8', 'latin1') using `.decode_from('your_encoding')`. For example, `BinaPy(b'hello \xc3\xbc').decode_from('utf8').ascii()`
Upgrade
Version history
0.8.0latest on PyPI · released Jan 19, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
16
Amazon
1
OpenAI (training)
1
Resources