Skip to main content

Supyr Struct

PyPI version GitHub version

Supyr Struct is an extensible and powerful binary data parsing, editing, and serializing library for Python 3.

Supyr's parsing and serializing is declarative, meaning that rather than write code to handle parsing and serializing data, you instead create a description of the structure using various FieldTypes. These descriptions are used by BlockDef objects to build Blocks, which represent/contain the parsed data. A BlockDef is simply a constructor object that scans its description for errors on initialization and uses it for creating Blocks.

Supyr provides a large collection of FieldTypes, ranging from atomic data types(floats and ints of various sizes) to hierarchical structures(structs, containers, and arrays) and logical structures and wrappers(switches and unions).

For a detailed overview of the more abstract concepts and features of Supyr, read the text files in the 'docs' folder.

Changelog

Check out the changelog here.

License

This project is licensed under the MIT License, check out the details and author info here.

Installing

You'll need Python 3.5 or higher.

In your terminal execute:

python3 -m pip install supyr_struct

or, you can clone/download this repo and run the setup.py:

git clone git@github.com:Sigmmma/supyr_struct.git
cd supyr_struct
python3 -m pip install .

Examples

Heres a small example of defining a structure using a BlockDef and FieldTypes and using it to create a Block.

>>> from supyr_struct import *
>>>
>>>
>>> asdf = BlockDef('some_block',
... UInt32('some_int'),
... BytesRaw('some_bytes', SIZE=16),
... ENDIAN='>')
>>>
>>>
>>> test_block = asdf.build()
>>> test_block.some_int = 1337
>>> test_block['some_bytes'] = b'here\'s a cstring\x00'
>>>
>>> print('test_block:', test_block)
test_block: [ Container, entries:2, some_block
    [ UInt32, size:4, some_int, 1337 ]
    [ BytesRaw, size:16, some_bytes, <RAWDATA> ]
    ]
>>>
>>>
>>> test_block.serialize()
BytearrayBuffer(b"\x00\x00\x059here\'s a cstring\x00")

Supyr allows forcing endianness to be either big, little, or back to normal on a library scale and/or on individual FieldTypes.

>>> field_types.FieldType.force_little()
>>> test_block.serialize()
BytearrayBuffer(b"9\x05\x00\x00here\'s a cstring\x00")
>>>
>>> field_types.FieldType.force_normal()
>>> test_block.serialize()
BytearrayBuffer(b"\x00\x00\x059here\'s a cstring\x00")
>>>
>>> field_types.FieldType.force_big()
>>> test_block.serialize()
BytearrayBuffer(b"\x00\x00\x059here\'s a cstring\x00")
>>>
>>> field_types.FieldType.force_little()
>>> test_block.serialize()
BytearrayBuffer(b"9\x05\x00\x00here\'s a cstring\x00")

Take a look at the examples module for some ready-to-run example programs that utilize Supyr in different ways.

Who do I talk to?

If you're having any issues with the library you can report them on our GitHub Issues page.

If the issue requires some more direct attention we'll drop a contact link.

Release files for supyr-struct 1.5.4

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

Source distribution (sdist)

Source distribution for supyr-struct 1.5.4
File Size Uploaded
supyr_struct-1.5.4.tar.gz 197.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for supyr-struct 1.5.4
File Interpreter ABI Platform
supyr_struct-1.5.4-py3-none-any.whl Python 3 none any Details

Total release size: 434.0 kB

Release files / supyr_struct-1.5.4.tar.gz

Download URL supyr_struct-1.5.4.tar.gz
Size 197.5 kB
Tags Source
SHA-256 checksum
How to use checksums
6ea341739d78b99dc18cccc02e659f9db12d5700e0c2cee4426b67b0684faea9
BLAKE2b-256 checksum
How to use checksums
4af701ea8e64dbd90b7f433b112929d7295442c5843f6213fb1abfc1e386cf75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

Release files / supyr_struct-1.5.4-py3-none-any.whl

Download URL supyr_struct-1.5.4-py3-none-any.whl
Size 236.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cf027a860ee364584d5cdb29c7ca58a14d3763e8805dc427b4f346ef58cc147d
BLAKE2b-256 checksum
How to use checksums
db537ec5d260832d73ffcc99a7db707e96d78aa09c80324be47d9da5657d521e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

Release history Release notifications | RSS feed

This release

1.5.4 This release

2 release files

1.5.3

2 release files

1.5.2

2 release files

1.5.1

2 release files

1.5.0

2 release files

1.4.1

2 release files

1.4.0

1 release file

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.9

2 release files

1.1.8

2 release files

1.1.6

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.2

2 release files

1.0.1

2 release files

0.9.16

2 release files

0.9.15

2 release files

0.9.14

1 release file

0.9.13

1 release file

0.9.12

2 release files

0.9.11

1 release file

0.9.10

1 release file

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