dill

Version:

0.3.7

Category:

data

Cluster:

Vali

Author / Distributor

dill on PyPI

Description

dill extends Python’s pickle module for serializing and de-serializing Python objects.

It supports a wider range of Python object types than pickle, including:

  • Lambdas and nested functions

  • Closures and generators

  • Class instances and interpreter sessions

This makes dill especially useful for parallel and distributed computing applications, including multiprocessing, where it allows passing more complex objects between processes.

Documentation

$ python -m dill --help

usage: python -m dill [-h] [-v] {check,info,diff} ...

options:
  -h, --help            show this help message and exit
  -v, --version         show version information

actions:
  {check,info,diff}
    check               check if pickle files can be unpickled
    info                show the contents of a pickle file
    diff                compare contents of two pickle files

Examples:
  python -m dill check file.pkl
  python -m dill info file.pkl
  python -m dill diff file1.pkl file2.pkl

Examples/Usage

  • Load Dill:

    $ module load data/dill/0.3.7-GCCcore-12.3.0
    
  • Unload the module:

    $ module unload data/dill/0.3.7-GCCcore-12.3.0
    
  • Serialize and restore a Python lambda:

    import dill
    
    # Define a lambda function
    f = lambda x: x * 2
    
    # Serialize to a file
    with open("lambda.pkl", "wb") as f_out:
        dill.dump(f, f_out)
    
    # Deserialize from file
    with open("lambda.pkl", "rb") as f_in:
        loaded_f = dill.load(f_in)
    
    print(loaded_f(10))  # Outputs: 20
    

Installation

Source Code on GitHub