METADATA 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. Metadata-Version: 2.1
  2. Name: dill
  3. Version: 0.3.6
  4. Summary: serialize all of python
  5. Home-page: https://github.com/uqfoundation/dill
  6. Download-URL: https://pypi.org/project/dill/#files
  7. Author: Mike McKerns
  8. Author-email: mmckerns@uqfoundation.org
  9. Maintainer: Mike McKerns
  10. Maintainer-email: mmckerns@uqfoundation.org
  11. License: BSD-3-Clause
  12. Project-URL: Documentation, http://dill.rtfd.io
  13. Project-URL: Source Code, https://github.com/uqfoundation/dill
  14. Project-URL: Bug Tracker, https://github.com/uqfoundation/dill/issues
  15. Platform: Linux
  16. Platform: Windows
  17. Platform: Mac
  18. Classifier: Development Status :: 5 - Production/Stable
  19. Classifier: Intended Audience :: Developers
  20. Classifier: Intended Audience :: Science/Research
  21. Classifier: License :: OSI Approved :: BSD License
  22. Classifier: Programming Language :: Python :: 3
  23. Classifier: Programming Language :: Python :: 3.7
  24. Classifier: Programming Language :: Python :: 3.8
  25. Classifier: Programming Language :: Python :: 3.9
  26. Classifier: Programming Language :: Python :: 3.10
  27. Classifier: Programming Language :: Python :: Implementation :: CPython
  28. Classifier: Programming Language :: Python :: Implementation :: PyPy
  29. Classifier: Topic :: Scientific/Engineering
  30. Classifier: Topic :: Software Development
  31. Requires-Python: >=3.7
  32. License-File: LICENSE
  33. Provides-Extra: graph
  34. Requires-Dist: objgraph (>=1.7.2) ; extra == 'graph'
  35. Provides-Extra: readline
  36. -----------------------------
  37. dill: serialize all of python
  38. -----------------------------
  39. About Dill
  40. ==========
  41. ``dill`` extends python's ``pickle`` module for serializing and de-serializing
  42. python objects to the majority of the built-in python types. Serialization
  43. is the process of converting an object to a byte stream, and the inverse
  44. of which is converting a byte stream back to a python object hierarchy.
  45. ``dill`` provides the user the same interface as the ``pickle`` module, and
  46. also includes some additional features. In addition to pickling python
  47. objects, ``dill`` provides the ability to save the state of an interpreter
  48. session in a single command. Hence, it would be feasible to save an
  49. interpreter session, close the interpreter, ship the pickled file to
  50. another computer, open a new interpreter, unpickle the session and
  51. thus continue from the 'saved' state of the original interpreter
  52. session.
  53. ``dill`` can be used to store python objects to a file, but the primary
  54. usage is to send python objects across the network as a byte stream.
  55. ``dill`` is quite flexible, and allows arbitrary user defined classes
  56. and functions to be serialized. Thus ``dill`` is not intended to be
  57. secure against erroneously or maliciously constructed data. It is
  58. left to the user to decide whether the data they unpickle is from
  59. a trustworthy source.
  60. ``dill`` is part of ``pathos``, a python framework for heterogeneous computing.
  61. ``dill`` is in active development, so any user feedback, bug reports, comments,
  62. or suggestions are highly appreciated. A list of issues is located at
  63. https://github.com/uqfoundation/dill/issues, with a legacy list maintained at
  64. https://uqfoundation.github.io/project/pathos/query.
  65. Major Features
  66. ==============
  67. ``dill`` can pickle the following standard types:
  68. - none, type, bool, int, float, complex, bytes, str,
  69. - tuple, list, dict, file, buffer, builtin,
  70. - python classes, namedtuples, dataclasses, metaclasses,
  71. - instances of classes,
  72. - set, frozenset, array, functions, exceptions
  73. ``dill`` can also pickle more 'exotic' standard types:
  74. - functions with yields, nested functions, lambdas,
  75. - cell, method, unboundmethod, module, code, methodwrapper,
  76. - methoddescriptor, getsetdescriptor, memberdescriptor, wrapperdescriptor,
  77. - dictproxy, slice, notimplemented, ellipsis, quit
  78. ``dill`` cannot yet pickle these standard types:
  79. - frame, generator, traceback
  80. ``dill`` also provides the capability to:
  81. - save and load python interpreter sessions
  82. - save and extract the source code from functions and classes
  83. - interactively diagnose pickling errors
  84. Current Release
  85. ===============
  86. The latest released version of ``dill`` is available from:
  87. https://pypi.org/project/dill
  88. ``dill`` is distributed under a 3-clause BSD license.
  89. Development Version
  90. ===================
  91. You can get the latest development version with all the shiny new features at:
  92. https://github.com/uqfoundation
  93. If you have a new contribution, please submit a pull request.
  94. Installation
  95. ============
  96. ``dill`` can be installed with ``pip``::
  97. $ pip install dill
  98. To optionally include the ``objgraph`` diagnostic tool in the install::
  99. $ pip install dill[graph]
  100. For windows users, to optionally install session history tools::
  101. $ pip install dill[readline]
  102. Requirements
  103. ============
  104. ``dill`` requires:
  105. - ``python`` (or ``pypy``), **>=3.7**
  106. - ``setuptools``, **>=42**
  107. Optional requirements:
  108. - ``objgraph``, **>=1.7.2**
  109. - ``pyreadline``, **>=1.7.1** (on windows)
  110. Basic Usage
  111. ===========
  112. ``dill`` is a drop-in replacement for ``pickle``. Existing code can be
  113. updated to allow complete pickling using::
  114. >>> import dill as pickle
  115. or::
  116. >>> from dill import dumps, loads
  117. ``dumps`` converts the object to a unique byte string, and ``loads`` performs
  118. the inverse operation::
  119. >>> squared = lambda x: x**2
  120. >>> loads(dumps(squared))(3)
  121. 9
  122. There are a number of options to control serialization which are provided
  123. as keyword arguments to several ``dill`` functions:
  124. * with *protocol*, the pickle protocol level can be set. This uses the
  125. same value as the ``pickle`` module, *DEFAULT_PROTOCOL*.
  126. * with *byref=True*, ``dill`` to behave a lot more like pickle with
  127. certain objects (like modules) pickled by reference as opposed to
  128. attempting to pickle the object itself.
  129. * with *recurse=True*, objects referred to in the global dictionary are
  130. recursively traced and pickled, instead of the default behavior of
  131. attempting to store the entire global dictionary.
  132. * with *fmode*, the contents of the file can be pickled along with the file
  133. handle, which is useful if the object is being sent over the wire to a
  134. remote system which does not have the original file on disk. Options are
  135. *HANDLE_FMODE* for just the handle, *CONTENTS_FMODE* for the file content
  136. and *FILE_FMODE* for content and handle.
  137. * with *ignore=False*, objects reconstructed with types defined in the
  138. top-level script environment use the existing type in the environment
  139. rather than a possibly different reconstructed type.
  140. The default serialization can also be set globally in *dill.settings*.
  141. Thus, we can modify how ``dill`` handles references to the global dictionary
  142. locally or globally::
  143. >>> import dill.settings
  144. >>> dumps(absolute) == dumps(absolute, recurse=True)
  145. False
  146. >>> dill.settings['recurse'] = True
  147. >>> dumps(absolute) == dumps(absolute, recurse=True)
  148. True
  149. ``dill`` also includes source code inspection, as an alternate to pickling::
  150. >>> import dill.source
  151. >>> print(dill.source.getsource(squared))
  152. squared = lambda x:x**2
  153. To aid in debugging pickling issues, use *dill.detect* which provides
  154. tools like pickle tracing::
  155. >>> import dill.detect
  156. >>> with dill.detect.trace():
  157. >>> dumps(squared)
  158. ┬ F1: <function <lambda> at 0x7fe074f8c280>
  159. ├┬ F2: <function _create_function at 0x7fe074c49c10>
  160. │└ # F2 [34 B]
  161. ├┬ Co: <code object <lambda> at 0x7fe07501eb30, file "<stdin>", line 1>
  162. │├┬ F2: <function _create_code at 0x7fe074c49ca0>
  163. ││└ # F2 [19 B]
  164. │└ # Co [87 B]
  165. ├┬ D1: <dict object at 0x7fe0750d4680>
  166. │└ # D1 [22 B]
  167. ├┬ D2: <dict object at 0x7fe074c5a1c0>
  168. │└ # D2 [2 B]
  169. ├┬ D2: <dict object at 0x7fe074f903c0>
  170. │├┬ D2: <dict object at 0x7fe074f8ebc0>
  171. ││└ # D2 [2 B]
  172. │└ # D2 [23 B]
  173. └ # F1 [180 B]
  174. With trace, we see how ``dill`` stored the lambda (``F1``) by first storing
  175. ``_create_function``, the underlying code object (``Co``) and ``_create_code``
  176. (which is used to handle code objects), then we handle the reference to
  177. the global dict (``D2``) plus other dictionaries (``D1`` and ``D2``) that
  178. save the lambda object's state. A ``#`` marks when the object is actually stored.
  179. More Information
  180. ================
  181. Probably the best way to get started is to look at the documentation at
  182. http://dill.rtfd.io. Also see ``dill.tests`` for a set of scripts that
  183. demonstrate how ``dill`` can serialize different python objects. You can
  184. run the test suite with ``python -m dill.tests``. The contents of any
  185. pickle file can be examined with ``undill``. As ``dill`` conforms to
  186. the ``pickle`` interface, the examples and documentation found at
  187. http://docs.python.org/library/pickle.html also apply to ``dill``
  188. if one will ``import dill as pickle``. The source code is also generally
  189. well documented, so further questions may be resolved by inspecting the
  190. code itself. Please feel free to submit a ticket on github, or ask a
  191. question on stackoverflow (**@Mike McKerns**).
  192. If you would like to share how you use ``dill`` in your work, please send
  193. an email (to **mmckerns at uqfoundation dot org**).
  194. Citation
  195. ========
  196. If you use ``dill`` to do research that leads to publication, we ask that you
  197. acknowledge use of ``dill`` by citing the following in your publication::
  198. M.M. McKerns, L. Strand, T. Sullivan, A. Fang, M.A.G. Aivazis,
  199. "Building a framework for predictive science", Proceedings of
  200. the 10th Python in Science Conference, 2011;
  201. http://arxiv.org/pdf/1202.1056
  202. Michael McKerns and Michael Aivazis,
  203. "pathos: a framework for heterogeneous computing", 2010- ;
  204. https://uqfoundation.github.io/project/pathos
  205. Please see https://uqfoundation.github.io/project/pathos or
  206. http://arxiv.org/pdf/1202.1056 for further information.