Skip to main content
Files added late

2 files were added to this release more than 14 days after its initial publication. Inspect the release files before installing.

Construct is a powerful declarative parser (and builder) for binary data.

Instead of writing imperative code to parse a piece of data, you declaratively define a data structure that describes your data. As this data structure is not code, you can use it in one direction to parse data into Pythonic objects, and in the other direction, convert (“build”) objects into binary data.

The library provides both simple, atomic constructs (such as integers of various sizes), as well as composite ones which allow you form hierarchical structures of increasing complexity. Construct features bit and byte granularity, easy debugging and testing, an easy-to-extend subclass system, and lots of primitive constructs to make your work easier:

  • Fields: raw bytes or numerical types

  • Structs and Sequences: combine simpler constructs into more complex ones

  • Adapters: change how data is represented

  • Arrays/Ranges: duplicate constructs

  • Meta-constructs: use the context (history) to compute the size of data

  • If/Switch: branch the computational path based on the context

  • On-demand (lazy) parsing: read only what you require

  • Pointers: jump from here to there in the data stream

Example

A PascalString is a string prefixed by its length:

>>> from construct import *
>>>
>>> PascalString = Struct("PascalString",
...     UBInt8("length"),
...     Bytes("data", lambda ctx: ctx.length),
... )
>>>
>>> PascalString.parse("\x05helloXXX")
Container({'length': 5, 'data': 'hello'})
>>> PascalString.build(Container(length = 6, data = "foobar"))
'\x06foobar'

Instead of specifying the length manually, let’s use an adapter:

>>> PascalString2 = ExprAdapter(PascalString,
...     encoder = lambda obj, ctx: Container(length = len(obj), data = obj),
...     decoder = lambda obj, ctx: obj.data
... )
>>> PascalString2.parse("\x05hello")
'hello'
>>> PascalString2.build("i'm a long string")
"\x11i'm a long string"

See more examples of file formats and network protocols in the repository.

Resources

Construct’s homepage is http://construct.readthedocs.org, where you can find all kinds of docs and resources. The library itself is developed on github; please use github issues to report bugs, and github pull-requests to send in patches. For general discussion or questions, please use the new discussion group.

Requirements

Construct should run on any Python 2.5-3.3 implementation.

Metadata

Release files for cython-construct 2.5.8

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

Files added late

2 files were uploaded more than 14 days after the first file in this release.

While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.

We recommend inspecting the release files before installing.

Source distribution (sdist)

Source distribution for cython-construct 2.5.8
File Size Uploaded
cython-construct-2.5.8.tar.gz 798.8 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for cython-construct 2.5.8
File
cython_construct-2.5.8-py3.5-win-amd64.egg Legacy Egg format - - Details
cython_construct-2.5.8-cp35-cp35m-win_amd64.whl CPython 3.5 CPython 3.5 pymalloc Windows x86-64 Details
cython_construct-2.5.8-cp35-cp35m-macosx_10_11_x86_64.whl CPython 3.5 CPython 3.5 pymalloc macOS 10.11+ x86-64 Details
cython-construct-2.5.8.macosx-10.11-x86_64.tar.gz Details

Total release size: 3.2 MB

Release files / cython-construct-2.5.8.tar.gz

Download URL cython-construct-2.5.8.tar.gz
Size 798.8 kB
Tags Source
SHA-256 checksum
How to use checksums
4de90d3ddd3cb7caa6acf67af74971d7a00168a0073319688b82dac535ccd374
BLAKE2b-256 checksum
How to use checksums
987e5d1635e7bc9a5e4aabbf3566f966ddff9026ce9724a733e580737ad8430b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / cython_construct-2.5.8-py3.5-win-amd64.egg

File added late

This file was uploaded more than 14 days after the first file in this release.

While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.

We recommend inspecting the release file before installing.

Download URL cython_construct-2.5.8-py3.5-win-amd64.egg
Size 499.7 kB
Tags Egg
SHA-256 checksum
How to use checksums
83db7c8e19e9cfc816a856e509660cec31203591df55c9fc9cdf6942e193c52d
BLAKE2b-256 checksum
How to use checksums
eb81f27428601bfbf5f37893992a416f3892b03c3d845a7a0fe3b7b544e0b913
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / cython_construct-2.5.8-cp35-cp35m-win_amd64.whl

File added late

This file was uploaded more than 14 days after the first file in this release.

While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.

We recommend inspecting the release file before installing.

Download URL cython_construct-2.5.8-cp35-cp35m-win_amd64.whl
Size 501.1 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
b014b5b1e4d9233b942af0f744d290fec325955389f155ee78f2b05ca8cde101
BLAKE2b-256 checksum
How to use checksums
41f6319ada77d400e5440cdf2f444c0ca847dd16d6a396ff478b3d59ef85dc95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / cython_construct-2.5.8-cp35-cp35m-macosx_10_11_x86_64.whl

Download URL cython_construct-2.5.8-cp35-cp35m-macosx_10_11_x86_64.whl
Size 681.0 kB
Tags CPython 3.5 CPython 3.5 pymalloc macOS 10.11+ x86-64
SHA-256 checksum
How to use checksums
d56ba05c88f6a6aac1c3fcdfd503b2174370d3e22edbdb9e50b4ec7cdcfc97ca
BLAKE2b-256 checksum
How to use checksums
73d66e845fe8b5c135a25b18e0f0d2d212148962b6d0382f61a156467644c502
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / cython-construct-2.5.8.macosx-10.11-x86_64.tar.gz

Download URL cython-construct-2.5.8.macosx-10.11-x86_64.tar.gz
Size 700.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ac3f0bd553141dbf9389144463063ca7a150e8d290d60bc8e6f50a8c877bdfd5
BLAKE2b-256 checksum
How to use checksums
8c96d56f5b04de31ea9eda847121ebc95e5fff47b518930772b0659ec256bc6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

2.5.8 This release

5 release files

2.5.7

16 release files

2.5.4

3 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