.PYO

PYO File

Python Optimized Bytecode File (legacy)
Ask a question
QUICK ANSWER

A .pyo file is a legacy Python optimized bytecode cache generated by running Python with the -O or -OO flag. The binary format is identical to a .pyc file. Python 3.5 eliminated the .pyo extension in 2015 (PEP 488), so if you see one today it comes from Python 2 or Python 3.0-3.4. You run it from the command line with a matching Python version, or decompile it back to .py with decompyle3 or uncompyle6.

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

On this page

19k+ extensions indexed
Last reviewed Jun 27, 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 PYO file format?

A .pyo file is a legacy Python optimized bytecode file produced by the CPython interpreter when run with the -O (optimize) or -OO flag. Passing -O strips assert statements from the compiled bytecode; passing -OO additionally removes all docstrings, reducing file size slightly.

Internally, .pyo files are byte-for-byte identical in format to .pyc files: a 16-byte header (4-byte version-specific magic number, 4-byte flags field, 4-byte timestamp or source hash, 4-byte source size) followed by a marshalled CPython code object. The optimization level is reflected only in the compiled content - never in the file header.

The .pyo extension was deprecated in Python 3.5 by PEP 488 (September 2015) and is no longer generated by any current Python release. From Python 3.5 onward, optimized bytecode is stored inside __pycache__ with names like module.cpython-311.opt-1.pyc (for -O) or .opt-2.pyc (for -OO). If you encounter a .pyo file today, it originates from Python 2 or Python 3.0-3.4 code.

.pyo files are not portable across CPython versions - the magic number changes with each release. Tools such as uncompyle6 (Python 2-3.8) and decompyle3 (Python 3.7-3.11) can decompile .pyo files back to approximate .py source, though accuracy varies by Python version and code complexity.

Security & safety

RISK: MEDIUM

A .pyo file executes as Python bytecode with all the capabilities of a Python script - file system access, network, subprocess execution. Never run a .pyo from an untrusted source. Antivirus software often does not scan .pyo content. Malicious Python apps are sometimes distributed as bytecode-only (.pyc/.pyo) to make reverse engineering harder, though decompilers can largely recover the source.

Format details

in a nutshell
FULL NAMEPython Optimized Bytecode File (legacy)aka Python compiled optimized file, PYO file
DEVELOPERPython Software Foundation (CPython)since Early CPython (1990s); same as .pyc but with optimizations (assert removal with -O; docstring removal with -OO)
MIME TYPEapplication/x-python-code
TYPEBinary CPython bytecode (same format as .pyc; generated with -O or -OO flag)
STANDARDOpen · royalty-free

Programs that open PYO files

Windows4 apps
Python (run the file) Open-source Run 'python file.pyo' from command prompt (Python 2 / 3.0-3.4 only). On Python 3.5+ rename to .pyc first or use the matching Python version.
decompyle3 (decompile to .py) Open-source pip install decompyle3 then 'decompyle3 file.pyo > file.py'. Works on Python 3.7-3.8 bytecode.
uncompyle6 (decompile Python 2-3.8) Open-source pip install uncompyle6 then 'uncompyle6 file.pyo > file.py'. Supports Python 2.4-3.8.
VS Code (view bytecode with extension) Open-source Rename .pyo to .pyc, then use the 'Python Disassembler' or 'Bytecode Viewer' extension to inspect opcodes.
macOS1 app
Python Open-source Same as Windows: 'python file.pyo' with matching Python version.
Linux1 app
Python Open-source Run 'python file.pyo' with the matching Python version. Most Linux distros include Python.
Web1 app
Decompiler.com (online decompile) Free Upload the .pyo file; the site decompiles Python bytecode (including .pyo) back to .py in the browser.

Technical details

deep spec
Format relationshipByte-for-byte identical file format to `.pyc`; distinguished only by the filename extension and optimization content
Header structure16-byte header: 4-byte version magic + 4-byte flags + 4-byte source mtime or hash + 4-byte source size
Body formatMarshalled CPython code object (bytecode instructions, constants pool, names, varnames, nested code objects)
Byte orderLittle-endian (CPython marshal serialization format)
Optimization level -OStrips `assert` statements from compiled bytecode
Optimization level -OOStrips `assert` statements and all docstrings from compiled bytecode
Deprecation`.pyo` extension eliminated in Python 3.5 (PEP 488, September 2015); not generated by any current Python release
Modern equivalent`module.cpython-3X.opt-1.pyc` (level 1) or `.opt-2.pyc` (level 2) stored in `__pycache__`
Version portabilityNot portable across CPython versions; the magic number in bytes 0-3 changes with each major CPython release
Integrity validationPython 3.7+ (PEP 552): optional SipHash of source stored in header flags; Python 2 / early 3: mtime comparison only
Decompilation tools`uncompyle6` (Python 2-3.8), `decompyle3` (Python 3.7-3.11)
Legacy scopeProduced only by Python 2 or Python 3.0-3.4; not encountered in projects targeting Python 3.5 or later
ReleasedEarly CPython (1990s); same as .pyc but with optimizations (assert removal with -O; docstring removal with -OO)
Latest versionDEPRECATED in Python 3.5 (PEP 488, September 2015) - .pyo extension no longer generated; replaced by .cpython-3X.opt-1.pyc / .opt-2.pyc naming
Open standardYes · royalty-free
Specificationpeps.python.org

PYO conversions

Community Q&A

asked by users
Ask a quick question
Get help from people who work with PYO 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 PYO files.

Frequently asked questions

What is a .pyo file?
A legacy Python optimized bytecode file - the compiled form of a .py script created with Python's -O or -OO optimization flag. Identical binary format to .pyc; generated by Python 2 and Python 3.0-3.4. Python 3.5+ no longer creates .pyo files.
How do I open a .pyo file?
You don't open it directly - Python runs it automatically. To read its content, use decompyle3 or uncompyle6 to decompile it back to .py source code, or rename to .pyc and use a bytecode disassembler.
Can I delete .pyo files?
Yes - .pyo files are bytecode caches. Python recreates them if needed. Deleting them does not break a working Python installation or app (assuming the .py source files are present).
What's the difference between .pyo and .pyc?
.pyo was compiled with -O (asserts removed) or -OO (docstrings also removed); .pyc was compiled without optimization. Binary format is identical. Python 3.5+ merged them into .opt-1.pyc / .opt-2.pyc.
Why does Python 3.5+ not create .pyo files?
PEP 488 (2015) eliminated .pyo because having two extensions for the same binary format was confusing. Optimization level is now encoded in the .pyc filename suffix (.opt-1.pyc, .opt-2.pyc).
How do I decompile a .pyo to get the Python source?
Use decompyle3 (Python 3.7-3.8) or uncompyle6 (Python 2-3.8): 'pip install decompyle3 && decompyle3 file.pyo'. Or upload to decompiler.com for a web-based option. Results may be imperfect, especially for -OO compiled files missing docstrings.

References

1PEP 488 - Elimination of PYO filespeps.python.org
2Python Docs - compileall moduledocs.python.org

Keep exploring

across the database

Top extensions this week

1.AQQAQQ Instant Messenger File
2.CRDOWNLOADChrome Partial Download File
3.JPGJPEG Image
4.DATProgram Data File (generic)
5.EXEWindows Executable (Portable Executable)
6.RPMSGRestricted Permission Message
7.PARTPartial Download File
8.BINCD/DVD Disc Image (BIN/CUE)
9.DBSQLite Database File
10.JSONJavaScript Object Notation 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