Skip to main content

MothPriest

Python module for creating intuitive file parsers.

Imagine you have a file with the following structure:

Field Size (Bytes) Value
Magic 6 "STRING"
StringSize 4 uint32 (little endian) size String in bytes
String StringSize string data for this file

MothPriest makes parsing and editing this file simple:

from io import BytesIO
from mothpriest.parsers import *

parser = BlockParser(
    "root",
    [
        MagicParser("STRING", "Magic"),
        IntegerParser("StringSize", size=4, little_endian=True, signed=False),
        StringParser("String", size="StringSize") # Note the reference back to StringSize
    ]
)

data = b"STRING\x1A\x00\x00\x00Lorem ipsum dolor sit amet"
with BytesIO(data) as buffer:
    parser(buffer)

assert parser['String'] == "Lorem ipsum dolor sit amet"

parser['String'] = "The quick brown fox jumps over the lazy dog"
# StringSize is now inconsistent with String, but there is no need to manually update

with BytesIO() as buffer:
    parser.unparse(buffer)
    buffer.seek(0)
    output_data = buffer.read()

# Note how StringSize is updated automatically
assert output_data == b"STRING\x2B\x00\x00\x00The quick brown fox jumps over the lazy dog"

Metadata

Release files for MothPriest 1.1.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 MothPriest 1.1.0
File Size Uploaded
mothpriest-1.1.0.tar.gz 13.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for MothPriest 1.1.0
File Interpreter ABI Platform
mothpriest-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 29.0 kB

Release files / mothpriest-1.1.0.tar.gz

Download URL mothpriest-1.1.0.tar.gz
Size 13.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ffc0907a5add4a27b3c60c09cf5c6b384c06510b182c8ee91d4ce624a76d74e4
BLAKE2b-256 checksum
How to use checksums
e618e6c02d83f3d460d57b2f83bb21fc418505c27d3f0e67c8753cb939aa29da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.11

Release files / mothpriest-1.1.0-py3-none-any.whl

Download URL mothpriest-1.1.0-py3-none-any.whl
Size 15.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aa6394b0ff25d550622088f5b912f2e272c80860c5eea33a88bc9d8e8dbdf17a
BLAKE2b-256 checksum
How to use checksums
57bf679a669f7107413483c64557affede852e480c19becfcf08fec4ecb0e9b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.11

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.0

2 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