python_marshal

Crates.iopython_marshal
lib.rspython_marshal
version
sourcesrc
created_at2025-01-11 21:42:31.905468
updated_at2025-01-30 13:34:29.230229
descriptionA Rust library for reading and writing Python marshal files.
homepage
repository
max_upload_size
id1512771
Cargo.toml error:TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
svenskithesource (Svenskithesource)

documentation

README

python_marshal

python_marshal is a Rust implementation of Python's marshal module. It provides functionality to read and write Python objects in a binary format. Additionally, it includes extensions for handling .pyc files directly. NOTE: This library only supports Python 3.10, 3.11, 3.12 and 3.13.

Installation

Use cargo add python_marshal to add this library to your project. You can also manually add it to your Cargo.toml file:

[dependencies]
python_marshal = "0.1.0"

Usage

Check out the documentation for more information. There are examples available in the examples directory.

Important to note: since Python allows for recursive references we have to store them separately. This means that we represent references to objects using Object::LoadRef(index) and Object::StoreRef(index). This is necessary to avoid infinite recursion when serializing and deserializing objects.

use python_marshal::load_bytes;

let data = b"r\x00\x00\x00\x00"; // Example byte data with a reference
let python_version = (3, 10);
let (object, references) = load_bytes(data, python_version.into()).unwrap();

references is a hashmap that maps the index of the reference to the object it references.

Testing

This library is very thoroughly tested. To ensure it can output the exact same bytes as the input data, we rewrite the whole standard library and compare the output with the input. It produces a 1:1 copy of the input data. You can run the tests with cargo test (integration tests only work on Windows).

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License

This project is licensed under the GNU GPL v3.0 license. See LICENSE for more information.

Commit count: 0

cargo fmt