Crate marshal_parser

Source
Expand description

§Parser for the “marshal” binary de/serialization format used by CPython

This crate implements a parser and some utilities for reading files in the “marshal” de/serialization format used internally in CPython. The exact format is not stable and can change between minor versions of CPython.

This crate supports parsing “marshal” dumps and pyc files that were written by CPython versions >= 3.6 and < 3.14.

There is a high-level and a low-level API, depending on how much access to the underlying data structures is needed. The low-level API also provides more flexibility since it does not require files, but can operate on plain bytes (Vec<u8>).

Reading a pyc file from disk:

use marshal_parser::{MarshalFile, Object};

let pyc = MarshalFile::from_pyc_path("mod.cpython-310.pyc").unwrap();
let object: Object = pyc.into_inner();

Reading a “marshal” dump (i.e. a file without pyc header):

use marshal_parser::{MarshalFile, Object};

let dump = MarshalFile::from_dump_path("dump.marshal", (3, 11)).unwrap();
let object: Object = dump.into_inner();

Structs§

CodeObject
Code objects as represented in the binary “marshal” format
MarshalFile
High-level parser for pyc and “marshal dump” files
MarshalObject
Parsed contents of a pyc file or “marshal dump”

Enums§

Error
Custom error type for distinguishing different failure modes
Object
Python objects as represented in the binary “marshal” format
ObjectType
Object type flag in the binary “marshal” format
StringType
String type flag for string-like objects