
Decompile and disassemble Python bytecode (.pyc/.pyo) back to readable source. Supports Python 2.0 - 3.15 (CPython, PyPy and other implementations). Written in Rust.
English | 简体中文
Decompile and disassemble Python bytecode (.pyc) from Python 2.0 through 3.15 back into readable source — written in Rust, no Python required at runtime, with an optional in-process pass through the cure simplifier.
pycdc program.pyc # decompile to stdout
pycdc dis program.pyc # disassemble (exception tables, line numbers, nested code)
--cure: folds the output through the cure simplifier/formatter in-process — no external binary, no Python — turning if cond: return a / return b into return a if cond else b and trimming ~10% of the lines--opcodesHomebrew (macOS & Linux):
brew install ejfkdev/tap/pycdc
Scoop (Windows):
scoop install https://raw.githubusercontent.com/ejfkdev/scoop-bucket/main/bucket/pycdc.json
The manifest selects x64 or arm64 automatically and installs both pycdc
and pycdas. To install by name instead, add the bucket once:
scoop bucket add ejfkdev https://github.com/ejfkdev/scoop-bucket
scoop install pycdc
cargo, from crates.io:
cargo install pycdc
Prebuilt binaries: raw executables (no archive wrapper) on the Releases page — Linux / Windows x86_64 + arm64, macOS arm64 + x86_64; Linux and Windows builds are UPX-compressed, macOS ships uncompressed.
From source:
cargo build --release # -> target/release/pycdc + pycdas
cargo install --path . # or install both binaries from a checkout
Every method provides both pycdc and pycdas.
# single file -> stdout, a file, or a directory
pycdc program.pyc > program.py
pycdc program.pyc -o program.py
pycdc program.pyc -o ./outdir/
# stdin (pipelines): - reads the pyc from stdin
cat program.pyc | pycdc -
# batch: mirror a directory tree (parallel by default, -j N to control,
# -q suppresses the per-file src -> dst lines)
pycdc ./pyc-corpus -o ./src-out
pycdc ./pyc-corpus # -> ./pyc-corpus-decompiled/
pycdc a.pyc b.pyc # -> a.py, b.py next to the inputs
pycdc ./pyc-corpus -o ./src-out -q -j 8
# raw marshal (no pyc header) with an explicit version
pycdc -v 3.8 payload.marshal
# disassembly — same CLI surface (files, dirs, stdin, -o/-j/-q)
pycdc dis program.pyc
pycdc dis ./pyc-corpus -o ./dis-out # -> mirrored .dis files
# the standalone `pycdas` binary is kept as a compatibility alias
# with byte-identical output
pycdas program.pyc
# optional simplification/formatting pass (cure, linked in-process)
pycdc --cure program.pyc
--cure is opt-in and purely cosmetic: pycdc's output is already
verified, so the default stays untouched. With it, conditionals collapse
into ternaries, quotes normalize to single quotes, and formatting is
reflowed:
# default # --cure
def classify(v): def classify(v):
if v is True: return 1 if v is True else 0
return 1
return 0
If the input cannot be parsed by cure, or if it contains
compiler-introspection metadata (__annotate__, co_freevars,
__conditional_annotations__, __classdict__) where simplifying could
change runtime behaviour, the file is emitted unchanged and a note goes
to stderr. The behavior matrix passes 754/754 both with and without
--cure, and all 528 corpus modules still compile under their own
interpreter with it. Because the pass deliberately rewrites statement
shapes (if/else → ternary), the corpus's bytecode-signature metric is
not meaningful for --cure output; judge it by the behavior matrix.
pycdc --help, pycdc dis --help and pycdas --help document every
flag. Exit codes: 0 success, 1 a file failed to process, 2 usage
error.
Apple Silicon, 526 real .pyc files (~9.5 MB, Python 2.6–3.14 stdlib):
| Scenario | Time | Peak RSS |
|---|---|---|
| Batch, parallel (default) | ≈0.05 s | ≈25 MB |
Batch, serial (-j 1) | ≈0.34 s | ≈13 MB |
| Largest single file (74 KB, incl. startup) | ≈5.5 ms | ≈4.4 MB |
| Process startup | ≈2 ms | — |
tools/fetch_realworld.sh sparse-checks-out one directory from each of
seven projects at its latest release tag, compiles every .py to
.pyc (compileall -b), and lands the tree in tests/realworld/
(git-ignored — the script is the way to recreate it):
| Project (tag) | modules | serial -j 1 | parallel (default) | recompiles | AST-identical¹ |
|---|---|---|---|---|---|
| yt-dlp (2026.08.19) | 1045 | 0.38 s | 0.08 s | 1045/1045 | 502/1045 |
| matplotlib (v3.11.2) | 253 | 0.28 s | 0.07 s | 253/253 | 60/253 |
| pandas (v3.0.5) | 1420 | 0.87 s | 0.16 s | 1420/1420 | 586/1420 |
| django (6.1.1) | 907 | 0.33 s | 0.12 s | 907/907 | 470/907 |
| sympy (1.14.0) | 1532 | 3.08 s | 1.62 s | 1532/1532 | 482/1532 |
| scikit-learn (1.9.1) | 671 | 0.42 s | 0.07 s | 671/671 | 216/671 |
| ansible (v2.21.4) | 583 | 0.24 s | 0.05 s | 583/583 | 186/583 |
| total | 6411 | 5.60 s | 2.17 s | 6411/6411 (100 %) | 2502/6411 |
¹ strict: docstring-stripped AST equal to the original source —
equivalent normalizations (an if/else instead of a ternary, a redundant
*()/**{} around an unpack, reordered keyword arguments) count as
differences, so treat it as a shape-fidelity floor rather than an error
rate. The parse/recompile column is the acceptance bar.
One pycdc process per project: ~0.87 ms per module serial, peak RSS
≈78 MB for the whole 6.4 k-module batch. All 6411 modules recompile;
the last family (a dict comprehension nested inside a generator
expression's element, call arguments included) was closed by the
community PR batch. Raw data: benchmarks/realworld.json,
harness: tools/bench_realworld.py.
Three independent harnesses, all runnable locally (need pyenv/uv interpreters 2.6–3.15):