https://github.com/thetacom/byteclasses
A Python package to manage and interact with binary data in a simple and structured manner.
https://github.com/thetacom/byteclasses
binary-data bytes data dataclasses package python python3
Last synced: 6 months ago
JSON representation
A Python package to manage and interact with binary data in a simple and structured manner.
- Host: GitHub
- URL: https://github.com/thetacom/byteclasses
- Owner: thetacom
- License: mit
- Created: 2024-04-12T01:58:35.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-13T22:02:49.000Z (over 1 year ago)
- Last Synced: 2024-04-14T13:07:54.548Z (over 1 year ago)
- Topics: binary-data, bytes, data, dataclasses, package, python, python3
- Language: Python
- Homepage: https://io.thetacom.info/byteclasses/
- Size: 1.47 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Byteclasses Python Package
[](https://pypi.python.org/pypi/byteclasses)
[](https://pypi.python.org/pypi/byteclasses)
[](https://libraries.io/pypi/byteclasses)
[](https://pypi.org/project/byteclasses/)
[](https://pypi.python.org/pypi/byteclasses)
[](https://pypi.python.org/pypi/byteclasses)
[](https://pypi.org/project/byteclasses/)
[](https://pypi.org/project/byteclasses/)
[](https://github.com/thetacom/byteclasses/actions/)
[](https://github.com/thetacom/byteclasses/actions/)
[](https://github.com/thetacom/byteclasses/actions/)
[](https://github.com/thetacom/byteclasses/actions/)
[](https://github.com/pre-commit/pre-commit)
[](https://github.com/charliermarsh/ruff)

A python package designed to ease data manipulation tasks and improve efficiency when handling binary data.
## Installation
```console
> pip install byteclasses
```
## Description
Byteclasses provides a variety of convenience wrapper classes to simplify data handling. These wrapper classes automatically pack and unpack data values.
Additionally, certains types, such as byteclass integers, impose type specific constraints. For example, assigning the value 256 to a `UInt8` will raise an `OverflowError` exception.
This library contains a variety of fixed size primitive byteclasses. These primitive classes can be used in conjunction with the byteclass collections to build more complicated data elements.
Similiar to a Python `dataclass`, byteclass collections are constructured using the `structure` or `union` class decorators.
Whereas dataclasses have fields, byteclass collections have members. Collection members must be a byteclass type and cannot have a default value unless using the `member` constructor function. Each member will be instantiated using its type hint as a factory.
A byteclass structure and union behaves similar to a C struct and union respectively.
The `ByteArray` and `String` collections can be instantiated directly using the provided classes.
## Byteclasses
- Primitives
- Generic - `BitField`, `Byte`, `Word`,`DWord`, `QWord`
- Characters - `UChar` (`Char`), `SChar`
- Floats - `Float16` (`Half`), `Float32` (`Float`),`Float64` (`Double`)
- Integers - `Int8`, `UInt8`, `Int16` (`Short`), `UInt16` (`UShort`), `Int32` (`Int`), `UInt32` (`UInt`), `Long`, `ULong`, `Int64` (`LongLong`), `UInt64` (`ULongLong`)
- Special - `ByteEnum`
- Collections
- `ByteArray` - Class
- `String` - Class
- `structure` - Class Decorator
- `union` - Class Decorator
## Simple Byteclass Structure Example
```python
from byteclasses.types.collections import structure
from byteclasses.types.primitives.integer import UInt8, UInt32
@structure
class MyStruct:
"""My custom byteclass structure."""
member1: UInt8
member2: UInt32
my_var = MyStruct()
```
## Docs
[Byteclasses Documentation](https://io.thetacom.info/byteclasses/)
## References
[C data types](https://en.wikipedia.org/wiki/C_data_types)