title: Where is the Python Pickle format formally defined?
body: <p>The Python language is formally defined in &quot;The Python Language Reference&quot; (<a href="https://docs.python.org/3/reference/index.html" rel="nofollow noreferrer">1</a>), which includes details about the grammar of Python source code. &quot;The Python Standard Library&quot; (<a href="https://docs.python.org/3/library/index.html" rel="nofollow noreferrer">2</a>) reference does a similar thing for the Python standard library, including the Pickle module (<a href="https://docs.python.org/3/library/pickle.html" rel="nofollow noreferrer">3</a>). However, at no point does this document actually explain the structure of the Pickle format.</p>
  <p>Based on the output of <code>pickletools</code>, and from reading some explanations of the format, it is evident that Pickle is:</p>
  <blockquote>
  <p>a stack based virtual machine which keeps track of objects. The file is just a list of serialized opcodes, the first one being expected to be the protocol version and the last one a stop opcode. When the stop opcode is met, the current object on the stack is popped.
  (<a href="http://spootnik.org/entries/2014/04/05/diving-into-the-python-pickle-formatt/" rel="nofollow noreferrer">4</a>).</p>
  </blockquote>
  <p>As far as I can tell, neither this structure nor the actual list of opcodes is actually officially defined any official Python document. Certain PEPs (<a href="https://www.python.org/dev/peps/pep-0307" rel="nofollow noreferrer">5</a>) (<a href="https://www.python.org/dev/peps/pep-3154/" rel="nofollow noreferrer">6</a>) (<a href="https://www.python.org/dev/peps/pep-0574/" rel="nofollow noreferrer">7</a>) describe <em>new</em> opcodes added in newer versions of the specification, but the original list of opcodes is nowhere to be found.</p>
  <p>Where is the Pickle format formally defined? Is it just the Python source code? If this is true, how would it be possible to create a new Python implementation if the standard library has no formal specification?</p>