METADATA 9.7 KB

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