#python #serde #serialization #pickle

serde-pickle

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

13 releases (2 stable)

new 1.1.0 Sep 22, 2021
0.6.3 Sep 3, 2021
0.6.2 Nov 18, 2020
0.6.1 Jul 9, 2020
0.2.0 Jul 30, 2016

#45 in Encoding

Download history 350/week @ 2021-06-06 314/week @ 2021-06-13 464/week @ 2021-06-20 367/week @ 2021-06-27 359/week @ 2021-07-04 373/week @ 2021-07-11 361/week @ 2021-07-18 428/week @ 2021-07-25 394/week @ 2021-08-01 310/week @ 2021-08-08 309/week @ 2021-08-15 564/week @ 2021-08-22 664/week @ 2021-08-29 630/week @ 2021-09-05 656/week @ 2021-09-12 390/week @ 2021-09-19

1,888 downloads per month
Used in 12 crates (11 directly)

MIT/Apache

155KB
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.0"

Requirements

Minimum supported Rust version is 1.41.1.

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–0.9MB
~18K SLoC