{
    "mode": "pydoc",
    "parameter": "pickletools",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/pydoc/pickletools/json",
    "generated": "2026-06-02T15:03:26Z",
    "sections": {
        "NAME": {
            "content": "pickletools - \"Executable documentation\" for the pickle module.\n",
            "subsections": []
        },
        "MODULE REFERENCE": {
            "content": "https://docs.python.org/3.10/library/pickletools.html\n\nThe following documentation is automatically generated from the Python\nsource files.  It may be incomplete, incorrect or include features that\nare considered implementation detail and may vary between Python\nimplementations.  When in doubt, consult the module reference at the\nlocation listed above.\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Extensive comments about the pickle protocols and pickle-machine opcodes\ncan be found here.  Some functions meant for external use:\n",
            "subsections": [
                {
                    "name": "genops",
                    "content": "Generate all the opcodes in a pickle, as (opcode, arg, position) triples.\n"
                },
                {
                    "name": "dis",
                    "content": "Print a symbolic disassembly of a pickle.\n"
                }
            ]
        },
        "FUNCTIONS": {
            "content": "",
            "subsections": [
                {
                    "name": "dis",
                    "content": "Produce a symbolic disassembly of a pickle.\n\n'pickle' is a file-like object, or string, containing a (at least one)\npickle.  The pickle is disassembled from the current position, through\nthe first STOP opcode encountered.\n\nOptional arg 'out' is a file-like object to which the disassembly is\nprinted.  It defaults to sys.stdout.\n\nOptional arg 'memo' is a Python dict, used as the pickle's memo.  It\nmay be mutated by dis(), if the pickle contains PUT or BINPUT opcodes.\nPassing the same memo object to another dis() call then allows disassembly\nto proceed across multiple pickles that were all created by the same\npickler with the same memo.  Ordinarily you don't need to worry about this.\n\nOptional arg 'indentlevel' is the number of blanks by which to indent\na new MARK level.  It defaults to 4.\n\nOptional arg 'annotate' if nonzero instructs dis() to add short\ndescription of the opcode on each line of disassembled output.\nThe value given to 'annotate' must be an integer and is used as a\nhint for the column where annotation should start.  The default\nvalue is 0, meaning no annotations.\n\nIn addition to printing the disassembly, some sanity checks are made:\n\n+ All embedded opcode arguments \"make sense\".\n\n+ Explicit and implicit pop operations have enough items on the stack.\n\n+ When an opcode implicitly refers to a markobject, a markobject is\nactually on the stack.\n\n+ A memo entry isn't referenced before it's defined.\n\n+ The markobject isn't stored in the memo.\n\n+ A memo entry isn't redefined.\n"
                },
                {
                    "name": "genops",
                    "content": "Generate all the opcodes in a pickle.\n\n'pickle' is a file-like object, or string, containing the pickle.\n\nEach opcode in the pickle is generated, from the current pickle position,\nstopping after a STOP opcode is delivered.  A triple is generated for\neach opcode:\n\nopcode, arg, pos\n\nopcode is an OpcodeInfo record, describing the current opcode.\n\nIf the opcode has an argument embedded in the pickle, arg is its decoded\nvalue, as a Python object.  If the opcode doesn't have an argument, arg\nis None.\n\nIf the pickle has a tell() method, pos was the value of pickle.tell()\nbefore reading the current opcode.  If the pickle is a bytes object,\nit's wrapped in a BytesIO object, and the latter's tell() result is\nused.  Else (the pickle doesn't have a tell(), and it's not obvious how\nto query its current position) pos is None.\n"
                },
                {
                    "name": "optimize",
                    "content": "Optimize a pickle string by removing unused PUT opcodes\n"
                }
            ]
        },
        "DATA": {
            "content": "all = ['dis', 'genops', 'optimize']\ntest = {'disassemblermemotest': '\\n>>> import pickle\\n>>> import...\n",
            "subsections": []
        },
        "FILE": {
            "content": "/usr/lib/python3.10/pickletools.py\n\n",
            "subsections": []
        }
    },
    "summary": "pickletools - \"Executable documentation\" for the pickle module.",
    "flags": [],
    "examples": [],
    "see_also": []
}