How to Decompile a Python `.pyc` File: Every Method, Tested
There are three ways to decompile a .pyc, and which one works depends entirely on the Python version it was built for. 1) An online decompiler (like our free .pyc Decompiler) — easiest, no install, handles Python 2.x–3.14. 2) A command-line tool — uncompyle6 or decompyle3 (≤3.8) are often the most complete but not bug-free; the pycdc CLI reads newer bytecode, with gaps (tested here). 3) From code, with the standard library — marshal + dis read the code object and its strings on any version, including ones no decompiler supports yet. I retested all three on Python 3.8 through 3.14 in October 2026 — results below.
A .pyc is compiled Python bytecode — the cached, runnable form of your .py. People ship it thinking the source is gone, but it decompiles back, and there's more than one way to do it. Which method you reach for depends on one thing: the Python version the `.pyc` was compiled for. Get that wrong and every tool throws an error.
So I built one sample script, compiled it with five Python versions (3.8, 3.10, 3.12, 3.13 and 3.14, using uv to fetch each interpreter), and ran every decompilation method against them — first in August, then again on 24 October 2026 with current versions of every tool. Real commands, real output, and an honest map of what works where. Here's the script every test uses:
The test file
API_KEY = "sk-demo-7c1f2a"def check(user, key):if key == "PRO-2026":return f"welcome {user}"return "access denied"print(check("mithun", "PRO-2026"))
It has the two things people hope a .pyc hides: a hard-coded key and a bit of logic. Let's see how well it hides them.
Method 1 — an online .pyc decompiler (easiest)
If you just want the source back with zero setup, an online decompiler is the fastest path. Our free .pyc Decompiler detects the Python version and decompiles anything from 2.x to 3.14. Drop the .pyc in and you get source out.
Here's the actual output it produced for the Python 3.14 build of the sample (retested 24 October 2026 — it came back in 2.4 seconds):
# Decompiled with https://pyobfuscate.devAPI_KEY = 'sk-demo-7c1f2a'def check(user, key):if key == 'PRO-2026':return f"welcome {user}"return 'access denied'print(check('mithun', 'PRO-2026'))
Complete: the key, the function, the PRO-2026 check, the f-string and the final return 'access denied' branch. Python 3.13 and 3.14 files get our deeper reconstruction pass (the 3.13 build took about 9 seconds); older files are decompiled instantly in your browser. One honest detail from testing: on the 3.8–3.12 builds the instant pass dropped the final return "access denied" line. The tool now checks every string in the bytecode against the output, spots gaps like that, and finishes the file with the deeper pass automatically. Decompilation is still reconstruction, not a byte-perfect inverse — check the edge branches of anything important.
Our decompiler reads the bytecode directly and doesn't need a matching Python interpreter installed — which is why it reaches versions the pip-based decompilers below can't.
Method 2 — a command-line decompiler (best fidelity on older bytecode)
For scripting and batch work, the classic tools are uncompyle6 and decompyle3, installed from pip. On the versions they support, their output is essentially the original file. I ran uncompyle6 on the Python 3.8 build (running it under Python 3.8 itself, via uv run):
# uncompyle6 version 3.9.3# Python bytecode version base 3.8.0 (3413)# Decompiled from: Python 3.8.20# Embedded file name: sample.py# Compiled at: 2026-10-24 14:08:28# Size of source mod 2**32: 172 bytesAPI_KEY = "sk-demo-7c1f2a"def check(user, key):if key == "PRO-2026":return f"welcome {user}"return "access denied"print(check("mithun", "PRO-2026"))
That's byte-for-byte the original, right down to the return "access denied" branch pycdc dropped — plus bonus metadata (the original filename and compile size) that uncompyle6 reads out of the header. The catch is version range: uncompyle6 tops out around Python 3.8, decompyle3 around 3.9. Point uncompyle6 at the 3.10 build and it stops with Unsupported Python version, 3.10, for decompilation. decompyle3 3.9.3 also recovered the whole 3.8 file, but printed about 220 lines of grammar trace before the source. For 3.10–3.12 bytecode, the usual command-line choice is the open-source `pycdc` (Decompyle++, built from C++).
Rule of thumb: .pyc from Python ≤3.9 → uncompyle6/decompyle3 for the cleanest source. Python 3.10–3.12 → the pycdc CLI, or our online tool (which also handles 3.13 and 3.14). No tool at hand → Method 3.
Method 3 — from code, with the standard library (works on any version)
Here's the method people forget: you don't strictly need a decompiler at all. A .pyc is a 16-byte header followed by a marshal-serialized code object — the exact thing the interpreter runs. Python's own marshal and dis modules read it on any version, because it's the interpreter's native format. That makes this the universal fallback.
I pointed it at the Python 3.14 build — the one none of the command-line decompilers can read:
import marshal, diswith open("sample.cpython-314.pyc", "rb") as f:header = f.read(16) # skip the 16-byte .pyc header (3.7+)code = marshal.load(f) # the module's code objectdef strings(c): # every string, including inside functionsfor k in c.co_consts:if isinstance(k, str):yield kelif hasattr(k, "co_consts"):yield from strings(k)print(list(strings(code)))dis.dis(code) # disassemble the logic
['sk-demo-7c1f2a', 'PRO-2026', 'welcome ', 'access denied', 'mithun', 'PRO-2026']# dis excerpt — the license check, in the clear:LOAD_CONST 0 ('PRO-2026')COMPARE_OP 88 (bool(==))LOAD_CONST 1 ('welcome ')LOAD_CONST 2 ('access denied')
No decompiler, no matching interpreter, no internet — and the API key, the license string, and the exact comparison are all right there. You don't get clean .py back (you get bytecode + constants), but for finding secrets or understanding logic it's often all you need, and it never hits a version wall.
This is why "just ship the .pyc" protects nothing: even when no decompiler supports your Python version, the string literals and control flow are readable straight out of the file with two standard-library calls.
Which tool for which Python version
The single most important thing about decompiling a .pyc is matching the tool to the bytecode version. Here's what I actually observed testing the sample from 3.8 to 3.14 (October 2026):
| Method | Python versions | Output | Setup |
|---|---|---|---|
| Our online .pyc Decompiler | 2.x–3.14 | Readable source | None — online |
pycdc CLI (Decompyle++) | 2.x–3.12 (3.13 partial, 3.14 no) | Readable source | C++ build |
decompyle3 | 3.7–3.9 | Near-original source | pip install |
uncompyle6 | 2.x–3.8 | Near-original source | pip install |
marshal + dis (stdlib) | Any version | Bytecode + constants | Built-in |
In my October 2026 rerun (pycdc's current master — its last commit is from April 2026), pycdc decompiled 3.8–3.12 but dropped the final return, returned a partial result on 3.13 (Unsupported opcode: MAKE_FUNCTION and # WARNING: Decompyle incomplete), and rejected 3.14 with Bad MAGIC! — exactly as in August. On larger, real-world code it breaks far more often — see the tested pycdc guide. Decompiler support always lags new Python releases by a while — so for a brand-new version, Method 3 is your bridge until the tools catch up. (Decompiler version support is a moving target; "my version isn't supported yet" is a delay, not a defense — see decompiling a .pyc.)
What this means if you want to protect your code
Every method above recovers either your source or your secrets, so shipping .pyc instead of .py is not protection — it's a cache format. If the goal is to make a .pyc genuinely hard to read, the fix is to change what gets compiled in the first place:
- Obfuscate the source before compiling. A decompiler can only give back the source that was compiled — so if you rename every identifier and encrypt the string literals first, the decompiled output is that mangled, encrypted version, not your real code. Our free Python Obfuscator does this at the AST level.
- Keep real secrets off the client. As the tests show, a hard-coded key survives every format. Load keys from the environment or your own backend — see how to protect API keys in Python.
- For the strongest bar, compile to a native module (
.pyd/.sovia Cython, or a Nuitka binary) so there's no bytecode tomarshal.loadat all. See Python to EXE.
More on the full picture in is Python obfuscation secure? and protecting Python source code.
Decompile a .pyc in your browser — free
Our free .pyc Decompiler turns a .pyc from Python 2.x–3.14 back into readable source. No install.
Open the .pyc DecompilerFree tools mentioned here
Related guides
Frequently asked questions
How do I decompile a Python .pyc file?
Pick a method by the .pyc's Python version. Easiest: an online decompiler like our free .pyc Decompiler (handles Python 2.x–3.14, no install). For a .pyc from Python ≤3.9, the uncompyle6 or decompyle3 CLI tools give near-original source. For any version — including brand-new ones no decompiler supports yet — read the code object directly with the standard library's marshal and dis modules.
What is the best pyc decompiler?
There's no single best — it depends on the Python version. For modern bytecode (3.10–3.12) the open-source pycdc CLI is the usual choice, and our free online decompiler covers everything up to 3.14. For Python ≤3.8 uncompyle6 is often the most complete, though it isn't bug-free. In my tests uncompyle6 even recovered a branch pycdc missed on newer bytecode.
Can I decompile a Python 3.14 .pyc file?
Yes. In October 2026 our free online .pyc Decompiler fully recovered a Python 3.14 test file — every string and both branches — in 2.4 seconds. The pycdc CLI rejects 3.14 files with "Bad MAGIC!", and uncompyle6/decompyle3 stop at Python 3.8/3.9. With no decompiler at all, Python's marshal + dis modules still show the strings and the logic.
Can you decompile any .pyc back to source?
Almost. Full-source decompilers (pycdc, uncompyle6, decompyle3) cover most Python versions, though support lags the newest releases. When no decompiler supports your version yet, you can still read everything that matters — string literals and control flow — straight from the code object with Python's built-in marshal and dis, so a .pyc never truly hides its contents.
Why does my .pyc decompiler say "Bad MAGIC" or fail to start?
The first four bytes of a .pyc are a magic number identifying the exact CPython version, and each decompiler only knows a range of versions. "Bad MAGIC" (pycdc) or a failure to start (uncompyle6/decompyle3) means the .pyc is from a Python version newer than the tool supports. Use a tool that covers that version, or read the bytecode with marshal + dis in the meantime.
How do I decompile a .pyc without installing anything?
Use an online decompiler such as our .pyc Decompiler — drop in the file and read the source, with nothing to install. Alternatively, if you have Python installed, marshal + dis are in the standard library and need no extra packages.
Does compiling to .pyc protect my Python source code?
No. A .pyc is cached bytecode that runs without the .py, stores string literals (including API keys) in plaintext, and decompiles back to near-original source. To actually protect code, obfuscate the source before compiling (rename identifiers, encrypt strings), keep secrets off the client, and for the strongest option compile to a native .pyd/.so or a Nuitka binary.