GPack is struct analog!
Project description
An analogue of Struct for python and even better!!
Installing:
pip install gpack
Example usage:
import gpack
gpack.setup()
"1234".pack("bi",2)
GPack replaces the python compiler for improved and convenient operation.
b - Big-Endian
l - Little-Endian
i - Int
I - Signed Int
s - String
o - Bool
n - Bytes
> - Big-endian
< - Little-endian
More usage:
test_data = [123, -123, "aboba", b"aboba", 1234, True, False, 321]
import gpack
gpack.setup()
packed = test_data.pack("bilIsniooi", 1, 1, 5, 10, 5, 1, 1, 2)
unpacked = packed.unpack("bi lI s n i o o i", 1, 1, 5, 10, 5, 1, 1, 2)
print(unpacked)
[123, -123, 'aboba', b'aboba\x00\x00\x00\x00\x00', 1234, True, False, 321]
You can use the spaces for ease of use
Format Specifiers with sizes
Numbers after formats specify sizes in bytes:
# Pack string (5 bytes) + int (4 bytes) + bool (1 byte)
packed = ["hello", 123, True].pack("s i o", 5, 4, 1)
# Unpack with same sizes
unpacked = packed.unpack("s i o", 5, 4, 1)
Also you can use without setup:
import gpack
gpack.pack([123],'i',1)
gpack.unpack(b'}','i',1)
You can use size inside arg 1:
import gpack
gpack.setup()
[123].pack("1i") # Pack 123 with unsinged int and size 1
[123].pack("i",1) # Pack 123 with unsinged int and size 1
To use from libs remove "gpack.setup()"
In latest version:
Fixed some bugs
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gpack-0.1.9.tar.gz.
File metadata
- Download URL: gpack-0.1.9.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14f0e37e506bdb24776ed02d57e3a18f580fee94acfd3df796026238f04f4f61
|
|
| MD5 |
005b4eef549423661d579acd58dea4ed
|
|
| BLAKE2b-256 |
ca8d53d9995a47779b01c337f5eb8878e42a127a5037fcfa42dae8d055926b49
|
File details
Details for the file gpack-0.1.9-py3-none-any.whl.
File metadata
- Download URL: gpack-0.1.9-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5a48ea4b60febe5bcbb575b230644df9cadaf44d1f796b4ea9f9f4d7c8040c2
|
|
| MD5 |
a40939933af2510361e88f2c1bd3c8fb
|
|
| BLAKE2b-256 |
e0f1e8226de641dd94e01e544c50746debf7c300c20e532337df5a343aa10e38
|