{"id":13460246,"url":"https://github.com/uqfoundation/dill","last_synced_at":"2025-05-13T18:04:54.276Z","repository":{"id":9218313,"uuid":"11031844","full_name":"uqfoundation/dill","owner":"uqfoundation","description":"serialize all of Python","archived":false,"fork":false,"pushed_at":"2025-04-29T16:46:08.000Z","size":1586,"stargazers_count":2345,"open_issues_count":191,"forks_count":181,"subscribers_count":24,"default_branch":"master","last_synced_at":"2025-05-06T17:13:42.263Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://dill.rtfd.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uqfoundation.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"uqfoundation","custom":"http://uqfoundation.org/pages/donate.html"}},"created_at":"2013-06-28T16:42:27.000Z","updated_at":"2025-04-30T18:51:26.000Z","dependencies_parsed_at":"2023-01-16T20:16:12.951Z","dependency_job_id":"e261d104-f8c7-47da-986f-526fdc9d48d4","html_url":"https://github.com/uqfoundation/dill","commit_stats":{"total_commits":672,"total_committers":47,"mean_commits":"14.297872340425531","dds":0.21875,"last_synced_commit":"c8b8c5775e572309a5ea787d9f897facfc9280d5"},"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uqfoundation%2Fdill","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uqfoundation%2Fdill/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uqfoundation%2Fdill/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uqfoundation%2Fdill/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uqfoundation","download_url":"https://codeload.github.com/uqfoundation/dill/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254000824,"owners_count":21997441,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T10:00:38.011Z","updated_at":"2025-05-13T18:04:54.253Z","avatar_url":"https://github.com/uqfoundation.png","language":"Python","readme":"dill\n====\nserialize all of Python\n\nAbout Dill\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``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[![Downloads](https://static.pepy.tech/personalized-badge/dill?period=total\u0026units=international_system\u0026left_color=grey\u0026right_color=blue\u0026left_text=pypi%20downloads)](https://pepy.tech/project/dill)\n[![Conda Downloads](https://img.shields.io/conda/dn/conda-forge/dill?color=blue\u0026label=conda%20downloads)](https://anaconda.org/conda-forge/dill)\n[![Stack Overflow](https://img.shields.io/badge/stackoverflow-get%20help-black.svg)](https://stackoverflow.com/questions/tagged/dill)\n---------------\nThe latest released version of ``dill`` is available from:\n    https://pypi.org/project/dill\n\n``dill`` is distributed under a 3-clause BSD license.\n\n\nDevelopment Version\n[![Support](https://img.shields.io/badge/support-the%20UQ%20Foundation-purple.svg?style=flat\u0026colorA=grey\u0026colorB=purple)](http://www.uqfoundation.org/pages/donate.html)\n[![Documentation Status](https://readthedocs.org/projects/dill/badge/?version=latest)](https://dill.readthedocs.io/en/latest/?badge=latest)\n[![Build Status](https://app.travis-ci.com/uqfoundation/dill.svg?label=build\u0026logo=travis\u0026branch=master)](https://app.travis-ci.com/github/uqfoundation/dill)\n[![codecov](https://codecov.io/gh/uqfoundation/dill/branch/master/graph/badge.svg)](https://codecov.io/gh/uqfoundation/dill)\n-------------------\nYou can get the latest development version with all the shiny new features at:\n    https://github.com/uqfoundation\n\nIf you have a new contribution, please submit a pull request.\n\n\nInstallation\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``dill`` requires:\n\n* ``python`` (or ``pypy``), **\u003e=3.9**\n* ``setuptools``, **\u003e=42**\n\nOptional requirements:\n\n* ``objgraph``, **\u003e=1.7.2**\n* ``gprof2dot``, **\u003e=2022.7.29**\n* ``pyreadline``, **\u003e=1.7.1** (on windows)\n\n\nBasic Usage\n-----------\n``dill`` is a drop-in replacement for ``pickle``. Existing code can be\nupdated to allow complete pickling using::\n\n    \u003e\u003e\u003e import dill as pickle\n\nor::\n\n    \u003e\u003e\u003e from dill import dumps, loads\n\n``dumps`` converts the object to a unique byte string, and ``loads`` performs\nthe inverse operation::\n\n    \u003e\u003e\u003e squared = lambda x: x**2\n    \u003e\u003e\u003e 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    \u003e\u003e\u003e import dill.settings\n    \u003e\u003e\u003e dumps(absolute) == dumps(absolute, recurse=True)\n    False\n    \u003e\u003e\u003e dill.settings['recurse'] = True\n    \u003e\u003e\u003e dumps(absolute) == dumps(absolute, recurse=True)\n    True\n\n``dill`` also includes source code inspection, as an alternate to pickling::\n\n    \u003e\u003e\u003e import dill.source\n    \u003e\u003e\u003e 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    \u003e\u003e\u003e import dill.detect\n    \u003e\u003e\u003e with dill.detect.trace():\n    \u003e\u003e\u003e     dumps(squared)\n    ┬ F1: \u003cfunction \u003clambda\u003e at 0x7fe074f8c280\u003e\n    ├┬ F2: \u003cfunction _create_function at 0x7fe074c49c10\u003e\n    │└ # F2 [34 B]\n    ├┬ Co: \u003ccode object \u003clambda\u003e at 0x7fe07501eb30, file \"\u003cstdin\u003e\", line 1\u003e\n    │├┬ F2: \u003cfunction _create_code at 0x7fe074c49ca0\u003e\n    ││└ # F2 [19 B]\n    │└ # Co [87 B]\n    ├┬ D1: \u003cdict object at 0x7fe0750d4680\u003e\n    │└ # D1 [22 B]\n    ├┬ D2: \u003cdict object at 0x7fe074c5a1c0\u003e\n    │└ # D2 [2 B]\n    ├┬ D2: \u003cdict object at 0x7fe074f903c0\u003e\n    │├┬ D2: \u003cdict object at 0x7fe074f8ebc0\u003e\n    ││└ # D2 [2 B]\n    │└ # D2 [23 B]\n    └ # 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----------------\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--------\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\n","funding_links":["https://github.com/sponsors/uqfoundation","http://uqfoundation.org/pages/donate.html"],"categories":["Python","Data Serialization","Data Format \u0026 I/O","语言资源库"],"sub_categories":["For Python","python"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuqfoundation%2Fdill","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuqfoundation%2Fdill","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuqfoundation%2Fdill/lists"}