Skip to main content

rustruct

Tests Latest Version Python Versions License Stars

A Rust core for parsing and building binary wire formats from Python -- construct's declarative ergonomics at struct's speed.

Like construct, you describe a layout once -- as a Struct subclass, or via compile() for schemas built at runtime -- with lengths, nested regions, and derived fields tracked and validated by the schema itself, not by hand. Unlike construct, that schema isn't walked field-by-field in Python on every call: it's compiled once into a program that Rust runs in a single Python -> Rust call for the whole structure, so parsing and building cost about what the equivalent hand-written struct code would.

Example

construct's own quick-start is a toy bitmap: a signature, a width and height, and width * height pixels. The same schema in rustruct, with one difference noted below:

from rustruct import U8, Struct, array, described, raw


class Bitmap(Struct):
    signature: bytes = raw(3, const=b"BMP")
    width: U8
    height: U8
    count: U8 = described(help="derived from len(pixels) on pack, like a length field")
    pixels: object = array(U8, count="count")


bmp = Bitmap(width=3, height=2, pixels=[7, 8, 9, 11, 12, 13])
assert bmp.pack() == b"BMP\x03\x02\x06\x07\x08\t\x0b\x0c\r"

The count field is the one difference from construct, which needs none: its schema is walked by a Python interpreter on every call, so width * height can be evaluated directly. rustruct compiles a schema once, and a count/len/size it derives has to be invertible back to one sibling field (a*ref + b) -- a product of two fields doesn't fit that shape, on either side. count above is that one field: like file_size in a real BMP header, the caller never computes it, it's derived from pixels at pack time.

Documentation

The full documentation is at mosquito.github.io/rustruct: a guided tutorial, task-oriented how-to guides, explanations of the schema and execution model, and an API reference.

Development

# Rust core (no Python)
cargo test -p rustruct-core

# Python package (maturin backend) + pytest
uv sync
uv run pytest

# Sphinx documentation (warnings are errors)
make test-docs

Metadata

Release files for rustruct 0.2.0

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

Source distribution (sdist)

Source distribution for rustruct 0.2.0
File Size Uploaded
rustruct-0.2.0.tar.gz 116.2 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for rustruct 0.2.0
File
rustruct-0.2.0-cp311-abi3-win_arm64.whl CPython 3.11 abi3 Windows ARM64 Details
rustruct-0.2.0-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details
rustruct-0.2.0-cp311-abi3-musllinux_1_2_x86_64.whl CPython 3.11 abi3 Linux musl 1.2+ x86-64 Details
rustruct-0.2.0-cp311-abi3-musllinux_1_2_aarch64.whl CPython 3.11 abi3 Linux musl 1.2+ ARM64 Details
rustruct-0.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 abi3 Linux glibc 2.17+ x86-64 Details
rustruct-0.2.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.11 abi3 Linux glibc 2.17+ ARM64 Details
rustruct-0.2.0-cp311-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl CPython 3.11 abi3 macOS 10.12+ universal2 (ARM64, x86-64), macOS 11.0+ ARM64, macOS 10.12+ x86-64 Details

Total release size: 4.0 MB

Release files / rustruct-0.2.0.tar.gz

Download URL rustruct-0.2.0.tar.gz
Size 116.2 kB
Tags Source
SHA-256 checksum
How to use checksums
cb3f2eeed8c8a8e19593278d7e0175e238ce248110ba0cabc36fcf14f21f1c99
BLAKE2b-256 checksum
How to use checksums
a70dcdac999f0edd5cde7e31f265d57107c81e3aec493fb0f1fe3eb98ac40dcd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.

Transparency log

Release files / rustruct-0.2.0-cp311-abi3-win_arm64.whl

Download URL rustruct-0.2.0-cp311-abi3-win_arm64.whl
Size 337.7 kB
Tags CPython 3.11 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
b197752d7ab162c40f82d458321c80a8814eba850a3a1560a4173994ab1173b5
BLAKE2b-256 checksum
How to use checksums
fadd99b2dffa0676f3074c6c1967b72cc654acc3a4b5b1c649cbf4fecb2e3d3e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.

Transparency log

Release files / rustruct-0.2.0-cp311-abi3-win_amd64.whl

Download URL rustruct-0.2.0-cp311-abi3-win_amd64.whl
Size 350.2 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
543dc0190f3b5cca4dc0d3478a700ad8f387772dceb45d88bd8999075f26d836
BLAKE2b-256 checksum
How to use checksums
7e799ff497e91596f7ec19840d411b133171a4963b640305d6cab49efa0951b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.

Transparency log

Release files / rustruct-0.2.0-cp311-abi3-musllinux_1_2_x86_64.whl

Download URL rustruct-0.2.0-cp311-abi3-musllinux_1_2_x86_64.whl
Size 702.2 kB
Tags CPython 3.11 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
7eb30279d8d69618d88fede01d8a78184a5e661d55ce4c7cba9305b70b4e12e5
BLAKE2b-256 checksum
How to use checksums
d14ece9c9a7cb6adc17ae2f7b8dbbf551535bbee179c09483dca280988aca647
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.

Transparency log

Release files / rustruct-0.2.0-cp311-abi3-musllinux_1_2_aarch64.whl

Download URL rustruct-0.2.0-cp311-abi3-musllinux_1_2_aarch64.whl
Size 660.7 kB
Tags CPython 3.11 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
5a64f26ca01230dbec3651410ed782ec65a42b2d579f518e520a6b6ca136c805
BLAKE2b-256 checksum
How to use checksums
09e18c10eba45ad6a5243d1fa639e87fb6fe5305232c0ff3a5ce569e364ae0d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.

Transparency log

Release files / rustruct-0.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL rustruct-0.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 486.9 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
911c4882a2b1c86452956fd2ac01aa713035546533f84f822badadbb9734a59b
BLAKE2b-256 checksum
How to use checksums
086e02f83b9867cff87e3821d6d8dc0e0237a1c2d2a2c64ce7cdf300df490de7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.

Transparency log

Release files / rustruct-0.2.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL rustruct-0.2.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 483.0 kB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
ff45dea02a4e8b2e66ef92ad1f5d6a4cdf8c46f16f5d404ccd3a4df0dbc113b0
BLAKE2b-256 checksum
How to use checksums
f3d6cf1c9c3b91b1f1bab8d020b1450b6958e098f028a8e55d0171e5d79050c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.

Transparency log

Release files / rustruct-0.2.0-cp311-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl

Download URL rustruct-0.2.0-cp311-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Size 844.3 kB
Tags CPython 3.11 abi3 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e2f6ba90846b4c3a27854f87fd1bef9406959e693eb0f181bc8a466e40e1caf2
BLAKE2b-256 checksum
How to use checksums
129bd46e09de39426d23cc85d6783d9b0cfdf6904969236c1acdeab0fa9e4369
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 2, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

8 release files

0.1.9

8 release files

0.1.8

8 release files

0.1.7

8 release files

0.1.6

8 release files

0.1.5

8 release files

0.1.4

7 release files

0.1.3

8 release files

0.1.1

8 release files

0.1.0

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