#serialization #python #pickle #serde

serde-pickle

A serde-based serialization library for Python's pickle format

15 releases (4 stable)

1.2.0 Nov 22, 2024
1.1.1 May 21, 2022
1.1.0 Sep 22, 2021
0.6.3 Sep 3, 2021
0.2.0 Jul 30, 2016

#79 in Encoding

Download history 21160/week @ 2024-08-23 20437/week @ 2024-08-30 25128/week @ 2024-09-06 27531/week @ 2024-09-13 24290/week @ 2024-09-20 25786/week @ 2024-09-27 28950/week @ 2024-10-04 20285/week @ 2024-10-11 21612/week @ 2024-10-18 21305/week @ 2024-10-25 17181/week @ 2024-11-01 14180/week @ 2024-11-08 17414/week @ 2024-11-15 16657/week @ 2024-11-22 15133/week @ 2024-11-29 14703/week @ 2024-12-06

66,639 downloads per month
Used in 82 crates (60 directly)

MIT/Apache

320KB
3.5K SLoC

Serde Pickle Serialization Library

Build Status Latest Version

Documentation

This crate is a Rust library for parsing and generating Python pickle streams. It is built upon Serde, a high performance generic serialization framework.

Installation

This crate works with Cargo and can be found on crates.io with a Cargo.toml like:

[dependencies]
serde = "1.0"
serde-pickle = "1.1"

Requirements

Minimum supported Rust version is 1.63.0.

Usage

As with other serde serialization implementations, this library provides toplevel functions for simple en/decoding of supported objects.

Example:

use std::collections::BTreeMap;

fn main() {
    let mut map = BTreeMap::new();
    map.insert("x".to_string(), 1.0);
    map.insert("y".to_string(), 2.0);

    // Serialize the map into a pickle stream.
    // The second argument are serialization options.
    let serialized = serde_pickle::to_vec(&map, Default::default()).unwrap();

    // Deserialize the pickle stream back into a map.
    // Because we compare it to the original `map` below, Rust infers
    // the type of `deserialized` and lets serde work its magic.
    // The second argument are additional deserialization options.
    let deserialized = serde_pickle::from_slice(&serialized, Default::default()).unwrap();
    assert_eq!(map, deserialized);
}

Serializing and deserializing structs and enums that implement the serde-provided traits is supported, and works analogous to other crates (using serde_derive).

Dependencies

~0.6–10MB
~106K SLoC