A sub-byte-struct-supporting Python serialization/deserialization library for Python 3.8.
Project description
bytemaker
What is it?
bytemaker is a Python 3.8-compatible library for bit-manipulation and byte serialization/deserialization. It brings C bitfield functionality over to Python version 3.8+. To that end, it provides methods and types for converting @dataclass-decorated classes.
What can you do with it?
- A
BitVector
class analogous to Python'sbytearray
class, but for sub-byte bit quantities.BitVector
supports all the methods you'd expect to have in a bit-centricbytearray
with a few extras, to boot. - A set of
BitTypes
classes, including various-sized buffers, unsigned/signed ints, floats, and strings, that have underlyingBitVector
representations. - Support for serializing/deserializing
@dataclass
annotated classes, where the annotations can beytypes
, Pythonctypes
(c_uint8
,ctypes.STRUCTURE
, etc.), or Python native typespytypes
(int
,bool
,char
,float
). Nested types? No problem! - Automagic support for handling any of the aforementioned objects via
aggregate_types.to_bits_aggregate
andaggregate_types.from_bits_aggregate
.
How do I install it?
Run python -m pip install bytemaker
.
Project intent
The main goal of the project is to ease development of projects working with compiled code (e.g. ROM hacking). As such, streaming features are currently deemphasized, although I may implement them at some later date.
Changelog
Version 0.9.2
(29 August 2024)
Bugfixes
pyproject.toml did not include subpackages for PyPi, so importing from PyPi was failing to include bitvector or bittypes
Other
Relaxed typechecking of inputs in bitvector.py from Literal[0, 1] to int when in sequences. This change allows users to use e.g. [0] * 5 without typecheckers having problems.
Removed some outdated references to BitArray in BitVector.pyi.
Version 0.9.1
Added magic methods to BitTypes classes.
Removed BitTypes' __hash__
functionality
Modified BitTypes' __repr__
to include endianness
Version 0.9.0
Bits
is now BitVector
. Its API has been changed to be much more similar to bytearray
. To that end, inline methods and alternative syntaxes have been winnowed where possible.
ytypes
are now BitTypes
, and, rather than extending from Bits
, now contain BitVectors
. This change was made so that, in the long run, uint:UInt8 + sint:SInt8 wouldn't be the same as concatenation, and so that str24[1] would grab the second element.
BitTypes
now have full support for endianness when casting to bytes
. Note that while the types have endianness, their underlying bit representations do not (because that wouldn't make much sense!). Usage of ctypes
still assumes development is done on a little-endian machine. This is the vast, vast, vast majority of consumer hardware today, unless you run a bi-endian machine and have set it to big-endian mode. This may not change; the remaining primary use of ctypes
is for non-chararray array types (to be resolved in a near-future version).
Upcoming deprecations:
(any BitType).to_bits()
and (any BitType).from_bits()
. This behavior should instead be replicated by (any BitType).bits
and (any BitType)(bits)
Version 0.8.3
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
File details
Details for the file bytemaker-0.9.2.tar.gz
.
File metadata
- Download URL: bytemaker-0.9.2.tar.gz
- Upload date:
- Size: 35.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b9021d08331e1ce671bd549a89981047c97157f12c69d8fb0fe1015e2832248 |
|
MD5 | 84f0cc68bbe1b04833d72cc508dd0457 |
|
BLAKE2b-256 | 7674927990a7f0db6c157d55b7db7778978507a56f791b17ebf285966226655d |
File details
Details for the file bytemaker-0.9.2-py3-none-any.whl
.
File metadata
- Download URL: bytemaker-0.9.2-py3-none-any.whl
- Upload date:
- Size: 38.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 160fe0957e2a18872a194e670285cfb350da49145fb88e8aa4623a0787e2564a |
|
MD5 | a5a741c7e39b51a11ded68905bed4514 |
|
BLAKE2b-256 | 3bacb3a2c89960121ebcaff3febd9bcca8b4cc2b00abc9ddc8f6ccbab77ba80c |