typedstruct
A wrapper around the struct built-in module
with support for typing, on top of
Python 3.7 dataclasses.
Example
For example, if you wanted to read the header of BMP files, you could write this:
from dataclasses import dataclass
from typedstruct import LittleEndianStruct, StructType
@dataclass
class BMPHeader(LittleEndianStruct):
type: int = StructType.uint16() # magic identifier: 0x4d42
size: int = StructType.uint32() # file size in bytes
reserved1: int = StructType.uint16() # not used
reserved2: int = StructType.uint16() # not used
offset: int = StructType.uint32() # image data offset in bytes
dib_header_size: int = StructType.uint32() # DIB header size in bytes
width_px: int = StructType.int32() # width of the image
height_px: int = StructType.int32() # height of the image
num_planes_px: int = StructType.uint16() # number of color planes
bits_per_pixel: int = StructType.uint16() # bits per pixel
compression: int = StructType.uint32() # compression type
image_size_bytes: int = StructType.uint32() # compression type
x_resolution_ppm: int = StructType.int32() # pixels per meter
y_resolution_ppm: int = StructType.int32() # pixels per meter
num_colors: int = StructType.int32() # number of colors
important_colors_colors: int = StructType.int32() # important colors
with open("some_file.bmp", "rb") as file:
raw_data = file.read(BMPHeader.get_size())
bmp_header = BMPHeader.unpack(raw_data)
assert bmp_header.type == 0x4D42
print(f"This image is {bmp_header.width_px}x{bmp_header.height_px}")
Metadata
Release files for typedstruct 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| typedstruct-0.1.0.tar.gz | 3.5 kB | Without provenance | Details for typedstruct-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| typedstruct-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for typedstruct-0.1.0-py3-none-any.whl |
Total release size: 7.1 kB
Release files / typedstruct-0.1.0.tar.gz
| Download URL | typedstruct-0.1.0.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5595230dc6b58a01572830689459307091d687123cf98d11398a359dddad032d
|
|
BLAKE2b-256 checksum How to use checksums |
034cd7951b49a9c6dc66bfc899bb3779e02c7eb8a65ec1efee186618a1954c00
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.10 CPython/3.8.5 Darwin/18.7.0
|
Release files / typedstruct-0.1.0-py3-none-any.whl
| Download URL | typedstruct-0.1.0-py3-none-any.whl |
|---|---|
| Size | 3.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6ae8e4e1680f6f65f937acbfe6e550fe4c8e67150eb708aeb4aa317b08f08da5
|
|
BLAKE2b-256 checksum How to use checksums |
54d361364ad347a6a51849f7ce1d0f888b53dd2ad3f3ba4dd03f37c318e304e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.10 CPython/3.8.5 Darwin/18.7.0
|
Security for typedstruct 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.