-----------------------------
dill: serialize all of Python
-----------------------------
About Dill
==========
``dill`` extends Python's ``pickle`` module for serializing and de-serializing
Python objects to the majority of the built-in Python types. Serialization
is the process of converting an object to a byte stream, and the inverse
of which is converting a byte stream back to a Python object hierarchy.
``dill`` provides the user the same interface as the ``pickle`` module, and
also includes some additional features. In addition to pickling Python
objects, ``dill`` provides the ability to save the state of an interpreter
session in a single command. Hence, it would be feasible to save an
interpreter session, close the interpreter, ship the pickled file to
another computer, open a new interpreter, unpickle the session and
thus continue from the 'saved' state of the original interpreter
session.
``dill`` can be used to store Python objects to a file, but the primary
usage is to send Python objects across the network as a byte stream.
``dill`` is quite flexible, and allows arbitrary user defined classes
and functions to be serialized. Thus ``dill`` is not intended to be
secure against erroneously or maliciously constructed data. It is
left to the user to decide whether the data they unpickle is from
a trustworthy source.
``dill`` is part of ``pathos``, a Python framework for heterogeneous computing.
``dill`` is in active development, so any user feedback, bug reports, comments,
or suggestions are highly appreciated. A list of issues is located at
https://github.com/uqfoundation/dill/issues, with a legacy list maintained at
https://uqfoundation.github.io/project/pathos/query.
Major Features
==============
``dill`` can pickle the following standard types:
- none, type, bool, int, float, complex, bytes, str,
- tuple, list, dict, file, buffer, builtin,
- Python classes, namedtuples, dataclasses, metaclasses,
- instances of classes,
- set, frozenset, array, functions, exceptions
``dill`` can also pickle more 'exotic' standard types:
- functions with yields, nested functions, lambdas,
- cell, method, unboundmethod, module, code, methodwrapper,
- methoddescriptor, getsetdescriptor, memberdescriptor, wrapperdescriptor,
- dictproxy, slice, notimplemented, ellipsis, quit
``dill`` cannot yet pickle these standard types:
- frame, generator, traceback
``dill`` also provides the capability to:
- save and load Python interpreter sessions
- save and extract the source code from functions and classes
- interactively diagnose pickling errors
Current Release
===============
The latest released version of ``dill`` is available from:
https://pypi.org/project/dill
``dill`` is distributed under a 3-clause BSD license.
Development Version
===================
You can get the latest development version with all the shiny new features at:
https://github.com/uqfoundation
If you have a new contribution, please submit a pull request.
Installation
============
``dill`` can be installed with ``pip``::
$ pip install dill
To optionally include the ``objgraph`` diagnostic tool in the install::
$ pip install dill[graph]
To optionally include the ``gprof2dot`` diagnostic tool in the install::
$ pip install dill[profile]
For windows users, to optionally install session history tools::
$ pip install dill[readline]
Requirements
============
``dill`` requires:
- ``python`` (or ``pypy``), **>=3.8**
- ``setuptools``, **>=42**
Optional requirements:
- ``objgraph``, **>=1.7.2**
- ``gprof2dot``, **>=2022.7.29**
- ``pyreadline``, **>=1.7.1** (on windows)
Basic Usage
===========
``dill`` is a drop-in replacement for ``pickle``. Existing code can be
updated to allow complete pickling using::
>>> import dill as pickle
or::
>>> from dill import dumps, loads
``dumps`` converts the object to a unique byte string, and ``loads`` performs
the inverse operation::
>>> squared = lambda x: x**2
>>> loads(dumps(squared))(3)
9
There are a number of options to control serialization which are provided
as keyword arguments to several ``dill`` functions:
* with *protocol*, the pickle protocol level can be set. This uses the
same value as the ``pickle`` module, *DEFAULT_PROTOCOL*.
* with *byref=True*, ``dill`` to behave a lot more like pickle with
certain objects (like modules) pickled by reference as opposed to
attempting to pickle the object itself.
* with *recurse=True*, objects referred to in the global dictionary are
recursively traced and pickled, instead of the default behavior of
attempting to store the entire global dictionary.
* with *fmode*, the contents of the file can be pickled along with the file
handle, which is useful if the object is being sent over the wire to a
remote system which does not have the original file on disk. Options are
*HANDLE_FMODE* for just the handle, *CONTENTS_FMODE* for the file content
and *FILE_FMODE* for content and handle.
* with *ignore=False*, objects reconstructed with types defined in the
top-level script environment use the existing type in the environment
rather than a possibly different reconstructed type.
The default serialization can also be set globally in *dill.settings*.
Thus, we can modify how ``dill`` handles references to the global dictionary
locally or globally::
>>> import dill.settings
>>> dumps(absolute) == dumps(absolute, recurse=True)
False
>>> dill.settings['recurse'] = True
>>> dumps(absolute) == dumps(absolute, recurse=True)
True
``dill`` also includes source code inspection, as an alternate to pickling::
>>> import dill.source
>>> print(dill.source.getsource(squared))
squared = lambda x:x**2
To aid in debugging pickling issues, use *dill.detect* which provides
tools like pickle tracing::
>>> import dill.detect
>>> with dill.detect.trace():
>>> dumps(squared)
┬ F1: <function <lambda> at 0x7fe074f8c280>
├┬ F2: <function _create_function at 0x7fe074c49c10>
│└ # F2 [34 B]
├┬ Co: <code object <lambda> at 0x7fe07501eb30, file "<stdin>", line 1>
│├┬ F2: <function _create_code at 0x7fe074c49ca0>
││└ # F2 [19 B]
│└ # Co [87 B]
├┬ D1: <dict object at 0x7fe0750d4680>
│└ # D1 [22 B]
├┬ D2: <dict object at 0x7fe074c5a1c0>
│└ # D2 [2 B]
├┬ D2: <dict object at 0x7fe074f903c0>
│├┬ D2: <dict object at 0x7fe074f8ebc0>
││└ # D2 [2 B]
│└ # D2 [23 B]
└ # F1 [180 B]
With trace, we see how ``dill`` stored the lambda (``F1``) by first storing
``_create_function``, the underlying code object (``Co``) and ``_create_code``
(which is used to handle code objects), then we handle the reference to
the global dict (``D2``) plus other dictionaries (``D1`` and ``D2``) that
save the lambda object's state. A ``#`` marks when the object is actually stored.
More Information
================
Probably the best way to get started is to look at the documentation at
http://dill.rtfd.io. Also see ``dill.tests`` for a set of scripts that
demonstrate how ``dill`` can serialize different Python objects. You can
run the test suite with ``python -m dill.tests``. The contents of any
pickle file can be examined with ``undill``. As ``dill`` conforms to
the ``pickle`` interface, the examples and documentation found at
http://docs.python.org/library/pickle.html also apply to ``dill``
if one will ``import dill as pickle``. The source code is also generally
well documented, so further questions may be resolved by inspecting the
code itself. Please feel free to submit a ticket on github, or ask a
question on stackoverflow (**@Mike McKerns**).
If you would like to share how you use ``dill`` in your work, please send
an email (to **mmckerns at uqfoundation dot org**).
Citation
========
If you use ``dill`` to do research that leads to publication, we ask that you
acknowledge use of ``dill`` by citing the following in your publication::
M.M. McKerns, L. Strand, T. Sullivan, A. Fang, M.A.G. Aivazis,
"Building a framework for predictive science", Proceedings of
the 10th Python in Science Conference, 2011;
http://arxiv.org/pdf/1202.1056
Michael McKerns and Michael Aivazis,
"pathos: a framework for heterogeneous computing", 2010- ;
https://uqfoundation.github.io/project/pathos
Please see https://uqfoundation.github.io/project/pathos or
http://arxiv.org/pdf/1202.1056 for further information.
Raw data
{
"_id": null,
"home_page": "https://github.com/uqfoundation/dill",
"name": "dill",
"maintainer": "Mike McKerns",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "mmckerns@uqfoundation.org",
"keywords": null,
"author": "Mike McKerns",
"author_email": "mmckerns@uqfoundation.org",
"download_url": "https://files.pythonhosted.org/packages/70/43/86fe3f9e130c4137b0f1b50784dd70a5087b911fe07fa81e53e0c4c47fea/dill-0.3.9.tar.gz",
"platform": "Linux",
"description": "-----------------------------\ndill: serialize all of Python\n-----------------------------\n\nAbout Dill\n==========\n\n``dill`` extends Python's ``pickle`` module for serializing and de-serializing\nPython objects to the majority of the built-in Python types. Serialization\nis the process of converting an object to a byte stream, and the inverse\nof which is converting a byte stream back to a Python object hierarchy.\n\n``dill`` provides the user the same interface as the ``pickle`` module, and\nalso includes some additional features. In addition to pickling Python\nobjects, ``dill`` provides the ability to save the state of an interpreter\nsession in a single command. Hence, it would be feasible to save an\ninterpreter session, close the interpreter, ship the pickled file to\nanother computer, open a new interpreter, unpickle the session and\nthus continue from the 'saved' state of the original interpreter\nsession.\n\n``dill`` can be used to store Python objects to a file, but the primary\nusage is to send Python objects across the network as a byte stream.\n``dill`` is quite flexible, and allows arbitrary user defined classes\nand functions to be serialized. Thus ``dill`` is not intended to be\nsecure against erroneously or maliciously constructed data. It is\nleft to the user to decide whether the data they unpickle is from\na trustworthy source.\n\n``dill`` is part of ``pathos``, a Python framework for heterogeneous computing.\n``dill`` is in active development, so any user feedback, bug reports, comments,\nor suggestions are highly appreciated. A list of issues is located at\nhttps://github.com/uqfoundation/dill/issues, with a legacy list maintained at\nhttps://uqfoundation.github.io/project/pathos/query.\n\n\nMajor Features\n==============\n\n``dill`` can pickle the following standard types:\n\n - none, type, bool, int, float, complex, bytes, str,\n - tuple, list, dict, file, buffer, builtin,\n - Python classes, namedtuples, dataclasses, metaclasses,\n - instances of classes,\n - set, frozenset, array, functions, exceptions\n\n``dill`` can also pickle more 'exotic' standard types:\n\n - functions with yields, nested functions, lambdas,\n - cell, method, unboundmethod, module, code, methodwrapper,\n - methoddescriptor, getsetdescriptor, memberdescriptor, wrapperdescriptor,\n - dictproxy, slice, notimplemented, ellipsis, quit\n\n``dill`` cannot yet pickle these standard types:\n\n - frame, generator, traceback\n\n``dill`` also provides the capability to:\n\n - save and load Python interpreter sessions\n - save and extract the source code from functions and classes\n - interactively diagnose pickling errors\n\n\nCurrent Release\n===============\n\nThe latest released version of ``dill`` is available from:\n\n https://pypi.org/project/dill\n\n``dill`` is distributed under a 3-clause BSD license.\n\n\nDevelopment Version\n===================\n\nYou can get the latest development version with all the shiny new features at:\n\n https://github.com/uqfoundation\n\nIf you have a new contribution, please submit a pull request.\n\n\nInstallation\n============\n\n``dill`` can be installed with ``pip``::\n\n $ pip install dill\n\nTo optionally include the ``objgraph`` diagnostic tool in the install::\n\n $ pip install dill[graph]\n\nTo optionally include the ``gprof2dot`` diagnostic tool in the install::\n\n $ pip install dill[profile]\n\nFor windows users, to optionally install session history tools::\n\n $ pip install dill[readline]\n\n\nRequirements\n============\n\n``dill`` requires:\n\n - ``python`` (or ``pypy``), **>=3.8**\n - ``setuptools``, **>=42**\n\nOptional requirements:\n\n - ``objgraph``, **>=1.7.2**\n - ``gprof2dot``, **>=2022.7.29**\n - ``pyreadline``, **>=1.7.1** (on windows)\n\n\nBasic Usage\n===========\n\n``dill`` is a drop-in replacement for ``pickle``. Existing code can be\nupdated to allow complete pickling using::\n\n >>> import dill as pickle\n\nor::\n\n >>> from dill import dumps, loads\n\n``dumps`` converts the object to a unique byte string, and ``loads`` performs\nthe inverse operation::\n\n >>> squared = lambda x: x**2\n >>> loads(dumps(squared))(3)\n 9\n\nThere are a number of options to control serialization which are provided\nas keyword arguments to several ``dill`` functions:\n\n* with *protocol*, the pickle protocol level can be set. This uses the\n same value as the ``pickle`` module, *DEFAULT_PROTOCOL*.\n* with *byref=True*, ``dill`` to behave a lot more like pickle with\n certain objects (like modules) pickled by reference as opposed to\n attempting to pickle the object itself.\n* with *recurse=True*, objects referred to in the global dictionary are\n recursively traced and pickled, instead of the default behavior of\n attempting to store the entire global dictionary.\n* with *fmode*, the contents of the file can be pickled along with the file\n handle, which is useful if the object is being sent over the wire to a\n remote system which does not have the original file on disk. Options are\n *HANDLE_FMODE* for just the handle, *CONTENTS_FMODE* for the file content\n and *FILE_FMODE* for content and handle.\n* with *ignore=False*, objects reconstructed with types defined in the\n top-level script environment use the existing type in the environment\n rather than a possibly different reconstructed type.\n\nThe default serialization can also be set globally in *dill.settings*.\nThus, we can modify how ``dill`` handles references to the global dictionary\nlocally or globally::\n\n >>> import dill.settings\n >>> dumps(absolute) == dumps(absolute, recurse=True)\n False\n >>> dill.settings['recurse'] = True\n >>> dumps(absolute) == dumps(absolute, recurse=True)\n True\n\n``dill`` also includes source code inspection, as an alternate to pickling::\n\n >>> import dill.source\n >>> print(dill.source.getsource(squared))\n squared = lambda x:x**2\n\nTo aid in debugging pickling issues, use *dill.detect* which provides\ntools like pickle tracing::\n\n >>> import dill.detect\n >>> with dill.detect.trace():\n >>> dumps(squared)\n \u252c F1: <function <lambda> at 0x7fe074f8c280>\n \u251c\u252c F2: <function _create_function at 0x7fe074c49c10>\n \u2502\u2514 # F2 [34 B]\n \u251c\u252c Co: <code object <lambda> at 0x7fe07501eb30, file \"<stdin>\", line 1>\n \u2502\u251c\u252c F2: <function _create_code at 0x7fe074c49ca0>\n \u2502\u2502\u2514 # F2 [19 B]\n \u2502\u2514 # Co [87 B]\n \u251c\u252c D1: <dict object at 0x7fe0750d4680>\n \u2502\u2514 # D1 [22 B]\n \u251c\u252c D2: <dict object at 0x7fe074c5a1c0>\n \u2502\u2514 # D2 [2 B]\n \u251c\u252c D2: <dict object at 0x7fe074f903c0>\n \u2502\u251c\u252c D2: <dict object at 0x7fe074f8ebc0>\n \u2502\u2502\u2514 # D2 [2 B]\n \u2502\u2514 # D2 [23 B]\n \u2514 # F1 [180 B]\n\nWith trace, we see how ``dill`` stored the lambda (``F1``) by first storing\n``_create_function``, the underlying code object (``Co``) and ``_create_code``\n(which is used to handle code objects), then we handle the reference to\nthe global dict (``D2``) plus other dictionaries (``D1`` and ``D2``) that\nsave the lambda object's state. A ``#`` marks when the object is actually stored.\n\n\nMore Information\n================\n\nProbably the best way to get started is to look at the documentation at\nhttp://dill.rtfd.io. Also see ``dill.tests`` for a set of scripts that\ndemonstrate how ``dill`` can serialize different Python objects. You can\nrun the test suite with ``python -m dill.tests``. The contents of any\npickle file can be examined with ``undill``. As ``dill`` conforms to\nthe ``pickle`` interface, the examples and documentation found at\nhttp://docs.python.org/library/pickle.html also apply to ``dill``\nif one will ``import dill as pickle``. The source code is also generally\nwell documented, so further questions may be resolved by inspecting the\ncode itself. Please feel free to submit a ticket on github, or ask a\nquestion on stackoverflow (**@Mike McKerns**).\nIf you would like to share how you use ``dill`` in your work, please send\nan email (to **mmckerns at uqfoundation dot org**).\n\n\nCitation\n========\n\nIf you use ``dill`` to do research that leads to publication, we ask that you\nacknowledge use of ``dill`` by citing the following in your publication::\n\n M.M. McKerns, L. Strand, T. Sullivan, A. Fang, M.A.G. Aivazis,\n \"Building a framework for predictive science\", Proceedings of\n the 10th Python in Science Conference, 2011;\n http://arxiv.org/pdf/1202.1056\n\n Michael McKerns and Michael Aivazis,\n \"pathos: a framework for heterogeneous computing\", 2010- ;\n https://uqfoundation.github.io/project/pathos\n\nPlease see https://uqfoundation.github.io/project/pathos or\nhttp://arxiv.org/pdf/1202.1056 for further information.\n",
"bugtrack_url": null,
"license": "BSD-3-Clause",
"summary": "serialize all of Python",
"version": "0.3.9",
"project_urls": {
"Bug Tracker": "https://github.com/uqfoundation/dill/issues",
"Documentation": "http://dill.rtfd.io",
"Download": "https://pypi.org/project/dill/#files",
"Homepage": "https://github.com/uqfoundation/dill",
"Source Code": "https://github.com/uqfoundation/dill"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "46d1e73b6ad76f0b1fb7f23c35c6d95dbc506a9c8804f43dda8cb5b0fa6331fd",
"md5": "647486e4fa04295d28cecf7a37a81139",
"sha256": "468dff3b89520b474c0397703366b7b95eebe6303f108adf9b19da1f702be87a"
},
"downloads": -1,
"filename": "dill-0.3.9-py3-none-any.whl",
"has_sig": false,
"md5_digest": "647486e4fa04295d28cecf7a37a81139",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 119418,
"upload_time": "2024-09-29T00:03:19",
"upload_time_iso_8601": "2024-09-29T00:03:19.344209Z",
"url": "https://files.pythonhosted.org/packages/46/d1/e73b6ad76f0b1fb7f23c35c6d95dbc506a9c8804f43dda8cb5b0fa6331fd/dill-0.3.9-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "704386fe3f9e130c4137b0f1b50784dd70a5087b911fe07fa81e53e0c4c47fea",
"md5": "78fcf5de86dec908c440baf7e5749c4e",
"sha256": "81aa267dddf68cbfe8029c42ca9ec6a4ab3b22371d1c450abc54422577b4512c"
},
"downloads": -1,
"filename": "dill-0.3.9.tar.gz",
"has_sig": false,
"md5_digest": "78fcf5de86dec908c440baf7e5749c4e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 187000,
"upload_time": "2024-09-29T00:03:20",
"upload_time_iso_8601": "2024-09-29T00:03:20.958666Z",
"url": "https://files.pythonhosted.org/packages/70/43/86fe3f9e130c4137b0f1b50784dd70a5087b911fe07fa81e53e0c4c47fea/dill-0.3.9.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-29 00:03:20",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "uqfoundation",
"github_project": "dill",
"travis_ci": true,
"coveralls": true,
"github_actions": false,
"tox": true,
"lcname": "dill"
}