cts, while ``byref`` only affects select objects. **kwds: extra keyword arguments passed to :py:class:`Pickler()`. Raises: :py:exc:`PicklingError`: if pickling fails. Examples: - Save current interpreter session state: >>> import dill >>> squared = lambda x: x*x >>> dill.dump_module() # save state of __main__ to /tmp/session.pkl - Save the state of an imported/importable module: >>> import dill >>> import pox >>> pox.plus_one = lambda x: x+1 >>> dill.dump_module('pox_session.pkl', module=pox) - Save the state of a non-importable, module-type object: >>> import dill >>> from types import ModuleType >>> foo = ModuleType('foo') >>> foo.values = [1,2,3] >>> import math >>> foo.sin = math.sin >>> dill.dump_module('foo_session.pkl', module=foo, refimported=True) - Restore the state of the saved modules: >>> import dill >>> dill.load_module() >>> squared(2) 4 >>> pox = dill.load_module('pox_session.pkl') >>> pox.plus_one(1) 2 >>> foo = dill.load_module('foo_session.pkl') >>> [foo.sin(x) for x in foo.values] [0.8414709848078965, 0.9092974268256817, 0.1411200080598672] - Use `refimported` to save imported objects by reference: >>> import dill >>> from html.entities import html5 >>> type(html5), len(html5) (dict, 2231) >>> import io >>> buf = io.BytesIO() >>> dill.dump_module(buf) # saves __main__, with html5 saved by value >>> len(buf.getvalue()) # pickle size in bytes 71665 >>> buf = io.BytesIO() >>> dill.dump_module(buf, refimported=True) # html5 saved by reference >>> len(buf.getvalue()) 438 *Changed in version 0.3.6:* Function ``dump_session()`` was renamed to ``dump_module()``. Parameters ``main`` and ``byref`` were renamed to ``module`` and ``refimported``, respectively. Note: Currently, ``dill.settings['byref']`` and ``dill.settings['recurse']`` don't apply to this function. )