METADATA 9.9 KB

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