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.1.9

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.1.9
File Size Uploaded
rustruct-0.1.9.tar.gz 110.8 kB Details

Built distributions (wheels)

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

Total release size: 3.9 MB

Release files / rustruct-0.1.9.tar.gz

Download URL rustruct-0.1.9.tar.gz
Size 110.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5daea95cb31a4cdd57dac81c8af91bef57c492f00df2c6eb07a824501c54ca37
BLAKE2b-256 checksum
How to use checksums
d6c0b7731a90c6556d4eb850794cdd85821da87b5e869ec8ad4c1f5723fd1ddf
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 1, 2026.

Transparency log

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

Download URL rustruct-0.1.9-cp311-abi3-win_arm64.whl
Size 332.3 kB
Tags CPython 3.11 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
cb950ef462bfa703c1d981f7f6897890faa58385a3e4f947993a0979de7f9e65
BLAKE2b-256 checksum
How to use checksums
704dcae95d018fe76204d8c69d4ab1407e35d9facb1bab624915637a3aedbecc
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 1, 2026.

Transparency log

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

Download URL rustruct-0.1.9-cp311-abi3-win_amd64.whl
Size 344.8 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
cb4f736569113903a1f664b2902034932897c9db8d176dd8882c720b1ea2e419
BLAKE2b-256 checksum
How to use checksums
3a8847bab577fd2b57915a5db9eadd6c17f62e9b68eb9e9b57220600d4e7f296
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 1, 2026.

Transparency log

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

Download URL rustruct-0.1.9-cp311-abi3-musllinux_1_2_x86_64.whl
Size 696.8 kB
Tags CPython 3.11 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
7a9cc4ce1100cf7224c8c2f9b53359b318c3a0d34f53eea92f1e7e96ee054c16
BLAKE2b-256 checksum
How to use checksums
afcf714a4f7a20b0841f676c4b6184df96f7f8e0ae64ce6678274a31906a2171
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 1, 2026.

Transparency log

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

Download URL rustruct-0.1.9-cp311-abi3-musllinux_1_2_aarch64.whl
Size 655.4 kB
Tags CPython 3.11 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
a127cde6598f8ee3e5c08d9fe0021ae418e3fa9b2115609a374b894ee2511bb6
BLAKE2b-256 checksum
How to use checksums
ab668441817441c7bc9d1e97374c66637f2c750a14f58ba764d0c43214711c24
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 1, 2026.

Transparency log

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

Download URL rustruct-0.1.9-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 481.6 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
2d4fb5de76f12d2a82e166779e1f2d56ffdd9f7f810c03a68145f73e9675294b
BLAKE2b-256 checksum
How to use checksums
6cc476d17d92ab53b94f376d0bfd7109bbed7579e667d0edaa282475740d3d0e
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 1, 2026.

Transparency log

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

Download URL rustruct-0.1.9-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 477.7 kB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
f32c5a43e888e8de0dab36d3ab60a926a869749b43dc1b50e6f345b2b047cb9a
BLAKE2b-256 checksum
How to use checksums
1cb95c25f147d7a04b9dcf13abd3905cc359d5618fe2b135cfeaf5d032db7436
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 1, 2026.

Transparency log

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

Download URL rustruct-0.1.9-cp311-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Size 839.0 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
28078b569b22e3cbdf3918b6d89f03bcfd2fda7de5285df4453a92e0fd6a8bfd
BLAKE2b-256 checksum
How to use checksums
730d601179a0625ef0061518b0de1435456cbf6c755cdc39ec9e5e3a41403f3e
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 1, 2026.

Transparency log

Release history Release notifications | RSS feed

0.2.0

8 release files

This release

0.1.9 This release

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