Skip to main content

An analogue of Struct for python!!

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

Release files for gpack 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gpack 0.2.3
File Size Uploaded
gpack-0.2.3.tar.gz 10.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gpack 0.2.3
File Interpreter ABI Platform
gpack-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 21.1 kB

Release files / gpack-0.2.3.tar.gz

Download URL gpack-0.2.3.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
533d8c73c59aece6815534722042ba9b756cf07ec785871da0d13200bec81688
BLAKE2b-256 checksum
How to use checksums
3de336f33d827ea98d0f05dc0a7efc294e6efbc3efe2a5365f3bedfab209a9dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / gpack-0.2.3-py3-none-any.whl

Download URL gpack-0.2.3-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
43ccacf18597343e3cb3235af19704315352a398376d2db4f3b450569bb2580f
BLAKE2b-256 checksum
How to use checksums
b76c7a5f0bee33d3d0a3987a7dd2461280ab0aef0a3cd09f54b71328893fa4a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.6

1 release file

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

1 release file

0.0.9

1 release file

0.0.8

1 release file

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page