A PYC file is a compiled output file generated from source code written in Python programming language. When PY file is run using Python interpreter, it is converted to bytecode for execution. At the same time, the compiled bytecode is also saved as .pyc file so as to reuse from cache at a later time if applicable.
Structure of PYC File Format
PYC files are in bytecode and their file format specifications are not available publicly. However, investigation by some sources show that the structure of a PYC file consists of:
A four-byte magic number - Simply two bytes that change with each change to the marshalling code, and then two bytes of 0d0a.
A four-byte modification timestamp - Unix modification timestamp of the source file that generated the .pyc, so that it can be recompiled if the source changes.
A marshalled code object - the output of marshal.dump of the code object that is a result of compiling the source file.