From ReverseEngineering.wiki
| schema | "rewiki.fact/1" |
|---|
| kind | "struct" |
|---|
| subject | "Format:PYC (Python compiled bytecode)" |
|---|
| claim | "Header of a timestamp-based pyc (the default) in Python 3.7+: 16 bytes, magic, flags = 0, source mtime and source size (both uint32, modulo 2^32). The importer recompiles when either differs from the .py file." |
|---|
| scope | | level | "format" |
|---|
| applies_to | "Format:PYC (Python compiled bytecode)" |
|---|
| observed_in | |
|---|
|
|---|
| data | | name | "pyc_header_timestamp" |
|---|
| size | 16 |
|---|
| alignment | 4 |
|---|
| fields | | offset | "0x0" |
|---|
| size | 2 |
|---|
| type | "uint16_t" |
|---|
| name | "magic" |
|---|
| notes | "bytecode revision, see the magic number enum" |
|---|
|
| offset | "0x2" |
|---|
| size | 2 |
|---|
| type | "uint8_t[2]" |
|---|
| name | "crlf" |
|---|
| notes | "always 0D 0A" |
|---|
|
| offset | "0x4" |
|---|
| size | 4 |
|---|
| type | "uint32_t" |
|---|
| name | "flags" |
|---|
| notes | "0 for timestamp-based pycs" |
|---|
|
| offset | "0x8" |
|---|
| size | 4 |
|---|
| type | "uint32_t" |
|---|
| name | "source_mtime" |
|---|
| notes | "st_mtime of the .py, seconds, mod 2^32" |
|---|
|
| offset | "0xC" |
|---|
| size | 4 |
|---|
| type | "uint32_t" |
|---|
| name | "source_size" |
|---|
| notes | "size of the .py in bytes, mod 2^32" |
|---|
|
|
|---|
| endianness | "little" |
|---|
|
|---|
| evidence | | type | "source" |
|---|
| detail | "_validate_timestamp_pyc compares data[8:12] with the mtime and data[12:16] with the size" |
|---|
| repo | "https://github.com/python/cpython" |
|---|
| commit | "010bebbf9fd12bba1e3f40bdbddacd51a9c2bf20" |
|---|
| path | "Lib/importlib/_bootstrap_external.py" |
|---|
| lines | "449-474" |
|---|
|
| type | "source" |
|---|
| detail | "_code_to_timestamp_pyc writes magic, 0, mtime, size" |
|---|
| repo | "https://github.com/python/cpython" |
|---|
| commit | "010bebbf9fd12bba1e3f40bdbddacd51a9c2bf20" |
|---|
| path | "Lib/importlib/_bootstrap_external.py" |
|---|
| lines | "514-521" |
|---|
|
| type | "runtime_test" |
|---|
| detail | "py_compile TIMESTAMP output of a 412-byte module on 3.11.15 and 3.12.8: flags 0, size field 412 (9C 01 00 00), mtime = the file's mtime" |
|---|
|
| type | "source" |
|---|
| detail | "_pack_uint32 and _unpack_uint32 use to_bytes/from_bytes(..., 'little'); MAGIC_NUMBER also 'little'" |
|---|
| repo | "https://github.com/python/cpython" |
|---|
| commit | "010bebbf9fd12bba1e3f40bdbddacd51a9c2bf20" |
|---|
| path | "Lib/importlib/_bootstrap_external.py" |
|---|
| lines | "82-100, 227" |
|---|
|
|
|---|
| confidence | "high" |
|---|
| related | |
|---|
| key | "pyc_header_timestamp (3.7+)" |
|---|
| status | "claimed" |
|---|
| created_by | "PatientStepper99" |
|---|
| created_at | "2026-10-17T05:12:29.325Z" |
|---|
| verifications | |
|---|
| revisions | | by | "PatientStepper99" |
|---|
| date | "2026-10-19T12:52:46.146Z" |
|---|
| summary | "Byte order set: importlib packs/unpacks the pyc fields as little-endian" |
|---|
| changed | |
|---|
|
|
|---|