.PYC

PYC File

Compiled Python Bytecode File
Ask a question
QUICK ANSWER

A .pyc file is compiled Python bytecode that CPython caches automatically to speed up startup. You do not normally need to open or touch it. To run one, use the matching Python version. To recover source code from a .pyc, use a decompiler such as decompyle3 or pycdc - results are approximate and may fail on newer Python versions.

Developer: Python Software Foundation (CPython) Category: Developer Files Open standard MIME: application/x-python-code
OPENS ON Windows macOS Linux
Related: .DO · .MD · .HEX · .XSD

On this page

19k+ extensions indexed
Last reviewed Jun 30, 2026

Not sure what your file is?

Drop any file into our identifier - we read just the first bytes to name the format.

Identify a file

What is the PYC file format?

.pyc files are used by the Python programming language. A .pyc file is an executable that contains compiled bytecode for a program written in Python source. Bytecode is a set of instructions for the interpreter to run the program without re-parsing the original source on every launch, which speeds up import and startup time.

.pyc files are accompanied by their related .py source files. Python compiles a .py file and saves the result in a .pyc file, which can then be used to run the program directly. Since Python 3.2, these cache files are placed in a __pycache__ subdirectory alongside the source, with the interpreter version embedded in the filename (for example, script.cpython-312.pyc).

Each .pyc file begins with a 16-byte header. The first two bytes are a version-specific magic number - it changes with every CPython release - followed by 0x0D 0x0A (CR LF) at bytes 2-3. The remaining header bytes hold either a source-file timestamp and size (the default) or a source file hash for deterministic, reproducible builds, a scheme introduced by PEP 552 in Python 3.7. After the header, the file contains a marshalled code object that can be inspected with Python's built-in dis module.

.pyc bytecode is tied to a specific CPython version - a file compiled under Python 3.11 will not load under Python 3.12. The older .pyo optimized-bytecode format was removed in Python 3.5; optimized builds now produce .opt-1.pyc or .opt-2.pyc files instead. To decompile a .pyc back toward readable source, tools such as uncompyle6, decompyle3, and pycdc (Decompyle++) are commonly used, though compatibility varies by Python version. On Windows, compiled extension modules use the related .pyd format.

Security & safety

RISK: MEDIUM

A .pyc is bytecode that the Python interpreter EXECUTES, so a malicious .pyc can run arbitrary code just like a script - never run a .pyc from an untrusted source. It is also a common technique for hiding malware (shipping only compiled bytecode). Conversely, distributing your own code as .pyc gives very weak protection: it can be decompiled and, at minimum, disassembled with the bundled 'dis' module, so it is NOT a real way to keep source secret. Deleting __pycache__ / .pyc files is safe - Python regenerates them automatically from the .py sources.

Format details

in a nutshell
FULL NAMECompiled Python Bytecode File
DEVELOPERPython Software Foundation (CPython)since Early CPython (1990s); current header layout (PEP 552 hash-based, deterministic) since Python 3.7, 2018
MIME TYPEapplication/x-python-code
TYPEBinary CPython bytecode (marshalled code object with a versioned header)
STANDARDOpen · royalty-free

Programs that open PYC files

Windows3 apps
Python (run it) Open-source Run it with the MATCHING Python version: 'python module.pyc'. The interpreter executes bytecode directly - but the version must match the one that compiled it.
decompyle3 / uncompyle6 (decompile) Open-source Recover source: 'pip install decompyle3' then 'decompyle3 file.pyc > file.py'. Works best for Python up to ~3.8; comments/formatting are lost.
pycdc (Decompyle++) Open-source For newer Python (3.9+) where uncompyle6 fails: build pycdc and run 'pycdc file.pyc'. Best-effort; accuracy on the latest versions is limited.
macOS2 apps
Python (run it) Open-source 'python3 module.pyc' with the matching interpreter version executes the bytecode.
uncompyle6 / decompyle3 (decompile) Open-source Install via pip and decompile to .py; same version caveats as on Windows.
Linux2 apps
Python (run it) Open-source Pre-installed on most distros: 'python3 module.pyc' (matching version) runs it; 'python3 -m dis module.pyc' shows the bytecode.
decompyle3 / pycdc (decompile) Open-source pip install decompyle3 (or build pycdc for 3.9+), then decompile the .pyc back toward .py.

Technical details

deep spec
DeveloperPython Software Foundation (CPython)
MIME typeapplication/x-python-code
File structureBinary - 16-byte versioned header followed by a marshalled Python code object
Magic numberBytes 0-1: version-specific 2-byte value (differs per CPython release); bytes 2-3: always 0x0D 0x0A (CR LF)
Header layout32-bit magic, 32-bit bit-field flags, then either 32-bit mtime + 32-bit source size (timestamp mode) or a 32-bit source hash (PEP 552 hash mode)
Cache directoryStored in __pycache__/ since Python 3.2; filename encodes the interpreter version, e.g. script.cpython-312.pyc
Version compatibilityEach CPython version writes a unique magic number; a .pyc from Python 3.11 will not load under 3.12 and vice versa
Platform portabilityPlatform-independent within the same CPython version - the same .pyc runs on Windows, macOS and Linux with a matching interpreter
Optimized variantspython -O and python -OO produce .opt-1.pyc and .opt-2.pyc (strip asserts and docstrings); the .pyo extension was retired in Python 3.5
Auto-generation controlCPython writes .pyc files automatically on import; suppressed by the -B flag or PYTHONDONTWRITEBYTECODE=1 environment variable
Disassembly / decompilationPython's built-in dis module disassembles bytecode; third-party tools uncompyle6, decompyle3, and pycdc (Decompyle++) attempt source reconstruction
Internal serialisation formatCode objects are serialised with the marshal module - a compact binary format distinct from pickle, not part of the stable public API
Hash-based buildsPEP 552 (Python 3.7+) introduced hash-based .pyc files: the header stores a source-file hash instead of mtime for reproducible builds
ReleasedEarly CPython (1990s); current header layout (PEP 552 hash-based, deterministic) since Python 3.7, 2018
Open standardYes · royalty-free
Specificationdocs.python.org

PYC conversions

Community Q&A

asked by users
Ask a quick question
Get help from people who work with PYC files. Be specific - include your system and software version.
No account needed · answers usually within a day

No questions yet - be the first to ask about PYC files.

Frequently asked questions

What is a .pyc file and can I delete it?
It's compiled Python bytecode that Python caches to start faster. You can safely delete .pyc files and __pycache__ folders - Python recreates them from the .py source the next time it runs.
How do I convert a .pyc back to .py source?
By decompiling it. Use decompyle3 or uncompyle6 for Python up to 3.8 ('decompyle3 file.pyc > file.py'), or pycdc for Python 3.9+. Results are approximate - comments and exact formatting are lost - and may fail on the newest Python versions.
Why won't my .pyc file run?
Almost always a version mismatch: a .pyc is tied to the exact CPython version that created it (the magic number). Run it with that same version, or get the original .py and let your Python recompile it.
Does shipping .pyc instead of .py hide my source code?
Only weakly. .pyc can be decompiled back to readable Python and always disassembled with the built-in 'dis' module. It deters casual viewing but is not real protection.
What's inside a __pycache__ folder?
Cached .pyc files named like module.cpython-311.pyc - one per imported module, tagged with the Python version. It's an automatic performance cache and is safe to remove.
Can I run a .pyc without the .py file?
Yes, if you have the matching Python version: 'python module.pyc'. The .py is only needed for editing or for Python to regenerate the cache.

References

1Python docs - dis (bytecode disassembler)docs.python.org
2PEP 552 - Deterministic pycspeps.python.org

Keep exploring

across the database

Top extensions this week

1.AQQAQQ Instant Messenger File
2.CRDOWNLOADChrome Partial Download File
3.MDMarkdown Document
4.BINCD/DVD Disc Image (BIN/CUE)
5.PARTPartial Download File
6.RPMSGRestricted Permission Message
7.NOMEDIAAndroid No-Media Marker File
8.EXEWindows Executable (Portable Executable)
9.AVIFAV1 Image File Format (AVIF)
10.ICSiCalendar data file

Related extensions

.DOStata Do-File
.MDMarkdown Document
.HEXIntel HEX File
.XSDXML Schema Definition
.MAPSource Map (JavaScript / CSS)
.CONFIGConfiguration File

Free file tools

An in-browser file identifier and image converter - everything runs on your device.

Open the toolbox

Browse file extensions A-Z