construct


Nameconstruct JSON
Version 2.10.70 PyPI version JSON
download
home_pagehttp://construct.readthedocs.org
SummaryA powerful declarative symmetric parser/builder for binary data
upload_time2023-11-29 08:44:49
maintainer
docs_urlNone
authorArkadiusz Bulski, Tomer Filiba, Corbin Simpson
requires_python>=3.6
licenseMIT
keywords construct kaitai declarative data structure struct binary symmetric parser builder parsing building pack unpack packer unpacker
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Construct 2.10
===================

Construct is a powerful **declarative** and **symmetrical** 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, to *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 and sequential 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
* Bitwise: splitting bytes into bit-grained fields
* 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 and parse only what you require
* Pointers: jump from here to there in the data stream
* Tunneling: prefix data with a byte count or compress it


Example
---------

A ``Struct`` is a collection of ordered, named fields::

    >>> format = Struct(
    ...     "signature" / Const(b"BMP"),
    ...     "width" / Int8ub,
    ...     "height" / Int8ub,
    ...     "pixels" / Array(this.width * this.height, Byte),
    ... )
    >>> format.build(dict(width=3,height=2,pixels=[7,8,9,11,12,13]))
    b'BMP\x03\x02\x07\x08\t\x0b\x0c\r'
    >>> format.parse(b'BMP\x03\x02\x07\x08\t\x0b\x0c\r')
    Container(signature=b'BMP')(width=3)(height=2)(pixels=[7, 8, 9, 11, 12, 13])

A ``Sequence`` is a collection of ordered fields, and differs from ``Array`` and ``GreedyRange`` in that those two are homogenous::

    >>> format = Sequence(PascalString(Byte, "utf8"), GreedyRange(Byte))
    >>> format.build([u"lalaland", [255,1,2]])
    b'\nlalaland\xff\x01\x02'
    >>> format.parse(b"\x004361789432197")
    ['', [52, 51, 54, 49, 55, 56, 57, 52, 51, 50, 49, 57, 55]]

            

Raw data

            {
    "_id": null,
    "home_page": "http://construct.readthedocs.org",
    "name": "construct",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "construct,kaitai,declarative,data structure,struct,binary,symmetric,parser,builder,parsing,building,pack,unpack,packer,unpacker",
    "author": "Arkadiusz Bulski, Tomer Filiba, Corbin Simpson",
    "author_email": "arek.bulski@gmail.com, tomerfiliba@gmail.com, MostAwesomeDude@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/02/77/8c84b98eca70d245a2a956452f21d57930d22ab88cbeed9290ca630cf03f/construct-2.10.70.tar.gz",
    "platform": "POSIX",
    "description": "Construct 2.10\n===================\n\nConstruct is a powerful **declarative** and **symmetrical** parser and builder for binary data.\n\nInstead 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, to *build* objects into binary data.\n\nThe library provides both simple, atomic constructs (such as integers of various sizes), as well as composite ones which allow you form hierarchical and sequential 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:\n\n* Fields: raw bytes or numerical types\n* Structs and Sequences: combine simpler constructs into more complex ones\n* Bitwise: splitting bytes into bit-grained fields\n* Adapters: change how data is represented\n* Arrays/Ranges: duplicate constructs\n* Meta-constructs: use the context (history) to compute the size of data\n* If/Switch: branch the computational path based on the context\n* On-demand (lazy) parsing: read and parse only what you require\n* Pointers: jump from here to there in the data stream\n* Tunneling: prefix data with a byte count or compress it\n\n\nExample\n---------\n\nA ``Struct`` is a collection of ordered, named fields::\n\n    >>> format = Struct(\n    ...     \"signature\" / Const(b\"BMP\"),\n    ...     \"width\" / Int8ub,\n    ...     \"height\" / Int8ub,\n    ...     \"pixels\" / Array(this.width * this.height, Byte),\n    ... )\n    >>> format.build(dict(width=3,height=2,pixels=[7,8,9,11,12,13]))\n    b'BMP\\x03\\x02\\x07\\x08\\t\\x0b\\x0c\\r'\n    >>> format.parse(b'BMP\\x03\\x02\\x07\\x08\\t\\x0b\\x0c\\r')\n    Container(signature=b'BMP')(width=3)(height=2)(pixels=[7, 8, 9, 11, 12, 13])\n\nA ``Sequence`` is a collection of ordered fields, and differs from ``Array`` and ``GreedyRange`` in that those two are homogenous::\n\n    >>> format = Sequence(PascalString(Byte, \"utf8\"), GreedyRange(Byte))\n    >>> format.build([u\"lalaland\", [255,1,2]])\n    b'\\nlalaland\\xff\\x01\\x02'\n    >>> format.parse(b\"\\x004361789432197\")\n    ['', [52, 51, 54, 49, 55, 56, 57, 52, 51, 50, 49, 57, 55]]\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A powerful declarative symmetric parser/builder for binary data",
    "version": "2.10.70",
    "project_urls": {
        "Documentation": "https://construct.readthedocs.io/en/latest/",
        "Homepage": "http://construct.readthedocs.org",
        "Issues": "https://github.com/construct/construct/issues",
        "Source": "https://github.com/construct/construct"
    },
    "split_keywords": [
        "construct",
        "kaitai",
        "declarative",
        "data structure",
        "struct",
        "binary",
        "symmetric",
        "parser",
        "builder",
        "parsing",
        "building",
        "pack",
        "unpack",
        "packer",
        "unpacker"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b2fb08b3f4bf05da99aba8ffea52a558758def16e8516bc75ca94ff73587e7d3",
                "md5": "39746844efc1594af00275da29205c5b",
                "sha256": "c80be81ef595a1a821ec69dc16099550ed22197615f4320b57cc9ce2a672cb30"
            },
            "downloads": -1,
            "filename": "construct-2.10.70-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "39746844efc1594af00275da29205c5b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 63020,
            "upload_time": "2023-11-29T08:44:46",
            "upload_time_iso_8601": "2023-11-29T08:44:46.876447Z",
            "url": "https://files.pythonhosted.org/packages/b2/fb/08b3f4bf05da99aba8ffea52a558758def16e8516bc75ca94ff73587e7d3/construct-2.10.70-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "02778c84b98eca70d245a2a956452f21d57930d22ab88cbeed9290ca630cf03f",
                "md5": "e880b97796c16ae362600b7e32339a7e",
                "sha256": "4d2472f9684731e58cc9c56c463be63baa1447d674e0d66aeb5627b22f512c29"
            },
            "downloads": -1,
            "filename": "construct-2.10.70.tar.gz",
            "has_sig": false,
            "md5_digest": "e880b97796c16ae362600b7e32339a7e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 86337,
            "upload_time": "2023-11-29T08:44:49",
            "upload_time_iso_8601": "2023-11-29T08:44:49.545010Z",
            "url": "https://files.pythonhosted.org/packages/02/77/8c84b98eca70d245a2a956452f21d57930d22ab88cbeed9290ca630cf03f/construct-2.10.70.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-29 08:44:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "construct",
    "github_project": "construct",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "construct"
}
        
Elapsed time: 0.43453s