Dill extends the standard pickle module to serialize and restore most built-in and user-defined Python types. It can also save and reload an entire interpreter session.
Overview
Dill is a Python package that broadens what you can turn into a byte stream and back again. It keeps the same interface as pickle while handling many types that pickle cannot, including lambdas, nested functions, modules, and code objects.
Beyond one-off object storage, dill can pickle an entire interpreter session so you can close Python, move the file elsewhere, and resume where you left off. A common use is sending Python objects over the network as bytes rather than only writing them to disk.
The library pickles standard scalars, containers, classes, instances, functions, and many descriptor-related types. It documents types it still cannot pickle, such as frames, generators, and tracebacks. Additional tools support saving interpreter sessions, extracting source from callables, and tracing pickling failures for debugging.
Dill is designed as a drop-in replacement: code can import dill as pickle or use dumps and loads directly. Serialization behavior can be tuned with keyword arguments and global settings. It is not meant to safely unpickle untrusted data; users must judge the source. The package is developed as part of the pathos heterogeneous computing framework.
Key features
- Drop-in pickle interface
- Serializes lambdas and nested functions
- Full interpreter session save and load
- dumps and loads byte-string API
- Configurable recursion and file-handle modes
- Source extraction via dill.source
- Pickle tracing via dill.detect
- Supports many built-in and user types
Use cases
- Sending Python objects over the network
- Checkpointing interpreter state
- Serializing arbitrary callables and classes
- Distributed and heterogeneous Python workflows