dill

raw JSON →
0.4.1 verified Tue May 12 auth: no python install: verified quickstart: verified

dill extends Python's pickle module for serializing and deserializing Python objects, supporting a wide range of built-in types. The current version is 0.4.1, released on January 19, 2026, with active development and regular updates.

pip install dill
error AttributeError: module 'dill._dill' has no attribute 'log'
cause This error typically occurs due to an incompatibility or version mismatch between the installed `dill` library and another dependent package (e.g., `datasets`, `nlp`) that expects a specific internal attribute of `dill` which has been removed or renamed in a newer version.
fix
Downgrade dill to a version compatible with the dependent library. For example, pip install dill==0.3.5.1 or pip install dill<0.3.6 if the issue is with log or PY3 (check the dependent library's requirements).
error ModuleNotFoundError: No module named 'dill'
cause The `dill` library is not installed in the Python environment where the code is being executed, or there is a naming conflict where a local script is named `dill.py`.
fix
Install the dill package using pip: pip install dill. If a local script is named dill.py, rename it to avoid conflicting with the library import.
error _pickle.PicklingError: Can't pickle <class '__main__.MyClass'>: it's not the same object as __main__.MyClass
cause While `dill` enhances Python's `pickle`, complex objects, especially dynamically created classes or objects defined directly in the `__main__` module, can still sometimes cause `PicklingError` if their exact context or definition isn't correctly preserved or recreated during deserialization, particularly across different environments or when `dill` is used with default `pickle`-like behavior for certain types.
fix
Ensure you are explicitly importing and using dill for serialization and deserialization (e.g., import dill; dill.dump(obj, file)). For classes defined in __main__ or when pickling modules, setting dill.settings['recurse'] = True before pickling can help dill trace and serialize global objects more comprehensively.
error UnpicklingError: pickle data was truncated
cause This error indicates that the `.pkl` file being loaded is incomplete or corrupted, most often because the file writing process (e.g., from `dill.dump()` or `dill.dump_session()`) was interrupted or failed to write all data to disk.
fix
Ensure that the dill.dump() or dill.dump_session() operation completes successfully, and that the file buffer is flushed (e.g., f.flush(); os.fsync(f.fileno()) for file objects) if writing to disk. Verify there is sufficient disk space when creating the pickled file, and regenerate the file if it is corrupted.
error TypeError: 'module' object is not callable
cause This error occurs when the `dill` module itself is mistakenly called as a function (e.g., `dill(...)`) instead of invoking its specific functions (like `dill.load()` or `dill.dumps()`). It can also rarely indicate an incorrect import of another module like `pprint` in older contexts.
fix
Correct the function call to use the appropriate dill method, such as dill.load(file) or dill.dumps(obj). If the error context involves pprint, ensure it's imported correctly, e.g., from pprint import pprint if pprint is intended to be used as a function.
breaking Function 'dump_session()' was renamed to 'dump_module()' in version 0.3.6. Parameters 'main' and 'byref' were renamed to 'module' and 'refimported', respectively.
fix Update function calls to 'dump_module()' with the new parameter names.
deprecated The 'dill.settings['byref']' and 'dill.settings['recurse']' settings do not apply to the 'dump_module()' function.
fix Avoid using these settings with 'dump_module()'.
python os / libc status wheel install import disk
3.10 alpine (musl) - - 0.14s 18.6M
3.10 slim (glibc) - - 0.10s 19M
3.11 alpine (musl) - - 0.23s 20.6M
3.11 slim (glibc) - - 0.20s 21M
3.12 alpine (musl) - - 0.20s 12.5M
3.12 slim (glibc) - - 0.20s 13M
3.13 alpine (musl) - - 0.19s 12.1M
3.13 slim (glibc) - - 0.20s 13M
3.9 alpine (musl) - - 0.14s 18.1M
3.9 slim (glibc) - - 0.12s 19M

A basic example demonstrating how to serialize and deserialize an object using dill.

import dill

# Serialize an object
obj = {'key': 'value'}
with open('obj.pkl', 'wb') as f:
    dill.dump(obj, f)

# Deserialize the object
with open('obj.pkl', 'rb') as f:
    loaded_obj = dill.load(f)
print(loaded_obj)