Registry / serialization / uncompyle6

uncompyle6

JSON →
library3.9.3pypypi✓ verified 84d ago

uncompyle6 is a cross-version Python bytecode decompiler. It allows you to convert Python bytecode (`.pyc` files or compiled function objects) back into human-readable Python source code. While the decompiler itself can run on modern Python versions (e.g., Python 3.6 to 3.12), it primarily supports decompiling bytecode from Python 2.x up to Python 3.8. The current version is 3.9.3, and it maintains an active release cadence, often aligning with major security conferences.

pip install uncompyle6
INSTALL
IMPORT
SIG · UNCOMPYLE6
U
uncompyle6
serializationpythonv3.9.3
Install
2.6s avg
Import
Disk
22MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.9.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 23.3MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.6s · import 0.000s · 24MB
22MB installed
● package 22MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

decompile_file
from uncompyle6 import decompile_file
from uncompyle6.decompile import decompile_file

This quickstart demonstrates how to programmatically decompile a `.pyc` file using `uncompyle6.decompile.decompile_file`. It first creates a dummy Python source file, compiles it into bytecode, and then uses `decompile_file` to print the reconstructed source code to standard output. Remember to install `uncompyle6` and its dependencies first.

import os import py_compile import sys import textwrap from pathlib import Path from uncompyle6.decompile import decompile_file # 1. Prepare: Create a dummy Python file and compile it to .pyc temp_dir = Path("uncompyle6_quickstart_temp") temp_dir.mkdir(exist_ok=True) source_path = temp_dir / "my_module.py" source_path.write_text(textwrap.dedent(""" def hello_world(): \"\"\"A simple greeting function.\"\"\" print("Hello from uncompyle6!") class MyUtil: def __init__(self, name): self.name = name def greet(self): return f"Greetings, {self.name}!" """)) # Compile the .py file to .pyc (ensures a standard .pyc structure) py_compile.compile(str(source_path), cfile=str(source_path.with_suffix('.pyc'))) pyc_path = source_path.with_suffix('.pyc') # 2. Decompile the .pyc file programmatically try: print(f"--- Decompiling {pyc_path.name} ---") # decompile_file takes the input .pyc path and an output file-like object decompile_file(pyc_path, sys.stdout) print(f"--- Decompilation complete ---") except Exception as e: print(f"An error occurred during decompilation: {e}") finally: # 3. Cleanup temporary files and directory if temp_dir.exists(): import shutil shutil.rmtree(temp_dir)
uncompyle6 --version
Debug
Known issues
gotchauncompyle6 can run on modern Python versions (e.g., 3.6-3.12), but it primarily supports decompiling bytecode up to Python 3.8. Attempting to decompile `.pyc` files from newer Python versions will likely result in errors or incorrect output.
fix
Verify the Python version that compiled the `.pyc` file. For bytecode from Python 3.9+, you might need to use other tools or wait for future uncompyle6 updates supporting those versions.
affects: All versions of uncompyle6 when used with Python 3.9+ bytecode.
breakingThe `xdis` library, a core dependency, frequently undergoes API changes. These changes can break `uncompyle6` if its bundled or required `xdis` version becomes incompatible with a newly installed or updated `xdis`.
fix
Always install `uncompyle6` using `pip install uncompyle6` to ensure compatible `xdis` versions are pulled in. If issues arise, try `pip install uncompyle6 --upgrade` to get the latest compatible versions of both libraries.
affects: Versions 3.7.0, 3.9.1, 3.9.2, 3.9.3 (and potentially others) due to explicit mentions in release notes.
gotchaWhen Python code is compiled with optimization flags (`python -O` or `python -OO`), certain elements like docstrings and `assert` statements are removed from the bytecode. Decompiling such `.pyc` files will result in missing these elements.
fix
If you need to recover docstrings or assert statements, ensure the original `.pyc` file was compiled without Python's optimization flags (`-O` or `-OO`).
affects: All versions, as this is a characteristic of Python's bytecode optimization.
Upgrade
Version history
3.9.3latest on PyPI · released Sep 29, 2025
Audit
Dependencies
xdisrequiredCore dependency for bytecode disassembly and parsing. Frequent API changes in xdis can necessitate uncompyle6 updates.
Agent activity
71 hits · last 30 days
node
67
OpenAI (training)
1
Resources
uncompyle6 — pip install uncompyle6 · libregistry