PyProtect is a powerful Python code obfuscation tool that helps protect your source code from reverse engineering and unauthorized analysis. It transforms readable Python scripts into obfuscated versions that maintain full functionality while being significantly harder to understand and decompile.
- Bytecode Obfuscation (
--bytecode): Converts Python source to compiled bytecode using marshal, removing all comments, docstrings, and formatting - Lambda Obfuscation (
--lambda): Uses nested lambda expressions and base64 encoding to hide code structure - Hybrid Obfuscation (
--hybrid): Combines bytecode compilation with lambda expressions for maximum obfuscation - Optional Compression (
--compress): Applies zlib compression to reduce file size and add complexity
- ✅ Preserves Functionality: Obfuscated code executes identically to the original
- ✅ No External Dependencies: Uses only Python standard library modules
- ✅ Cross-Platform Compatible: Works on any system with Python 3.x
- ✅ Simple CLI Interface: Easy-to-use command-line options
- ✅ Random Variable Names: Generates unique random names for variables in lambda/hybrid modes
- ✅ Smart Encoding: Automatically splits large encoded strings into chunks for better obfuscation
# Clone the repository
git clone <repository-url>
cd pyprotect
# Requirements
# Python >= 3.9 (standard library only)
# Run
python pyprotect.pypyprotect/
├── pyprotect.py # Main entry point
├── src/
│ ├── obfuscator.py # Obfuscation methods implementation
│ └── tools.py # Utility functions and argument handling
├── output/ # Generated obfuscated files (created automatically)
├── README.md
└── requirements.txt
python pyprotect.py [options]Options:
--help, -h Show this help message and exit
--input, -in FILE Input .py file to obfuscate
--output, -out FILE Output .py file (default: obfuscated_<input>)
Obfuscation Methods:
--bytecode Obfuscate using marshal bytecode loader
--lambda Obfuscate using nested lambda expressions
--hybrid Hybrid obfuscation combining bytecode and lambda
Additional Options:
--compress Enable compression (works with all methods)
# Basic bytecode obfuscation
python pyprotect.py --input script.py --bytecode
# Bytecode with compression
python pyprotect.py --input script.py --output protected.py --bytecode --compress
# Lambda obfuscation
python pyprotect.py --input myapp.py --lambda
# Hybrid obfuscation with compression (maximum protection)
python pyprotect.py --input sensitive.py --hybrid --compress
# Using short flags
python pyprotect.py -in test.py -out obf_test.py --hybrid- Compiles Python source code into bytecode using
compile() - Serializes bytecode with
marshal.dumps() - Optionally compresses with
zlib.compress() - Encodes to base64
- Generates a compact loader that reverses the process at runtime
Example Output:
import base64 as b, marshal as m;import zlib as z;a='<base64_data>';b=b.b64decode(a);b=z.decompress(b);c=m.loads(b);exec(c)- Encodes source code to base64
- Optionally splits into random chunks
- Creates nested lambda functions with random variable names
- Generates obfuscated code that decodes and executes at runtime
Example Output:
(lambda xkqwmzprtl: (lambda yjhgfdsakl: (lambda mnbvcxzaqw: (lambda poiuytrewq: poiuytrewq(mnbvcxzaqw(yjhgfdsakl(xkqwmzprtl))))(lambda asdfghjklz: exec(asdfghjklz)))(lambda asdfghjklz: asdfghjklz.decode('utf-8')))(lambda asdfghjklz: __import__('base64').b64decode(asdfghjklz)))('<base64_data>')- Compiles to bytecode (like
--bytecode) - Wraps in nested lambdas (like
--lambda) - Combines both techniques for maximum obfuscation
- Supports compression for additional protection
- Obfuscation is not encryption - it makes code harder to read, not impossible
- Determined attackers with sufficient time can still reverse engineer obfuscated code
- This tool is best used as one layer of a comprehensive security strategy
- Always use proper encryption for truly sensitive data
- Obfuscation does not protect against runtime analysis or debugging
✅ Protecting proprietary algorithms in commercial software
✅ Preventing casual inspection of source code
✅ Distributing Python applications while obscuring implementation details
✅ Adding a barrier against automated code analysis tools
✅ Securing business logic in deployed applications
❌ Protecting passwords, API keys, or sensitive credentials (use environment variables)
❌ Security-critical cryptographic operations (use proper encryption)
❌ Preventing all reverse engineering attempts (impossible with obfuscation alone)
Obfuscated files are automatically saved to the output/ directory with the specified filename. If no output filename is provided, the default format is obfuscated_<original_filename>.py.
- Python 3.6 or higher
- Standard library modules only (no external dependencies)
- File Size: Bytecode obfuscation typically increases file size by 30-40%. Compression can reduce this.
- Runtime: Minimal overhead - obfuscated code runs at nearly native speed after initial deobfuscation
- Memory: Small increase during initial loading for decompression/decoding
Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.
This tool is provided for legitimate purposes such as protecting intellectual property in commercial software. Users are responsible for ensuring their use complies with applicable laws and regulations. The authors are not responsible for any misuse of this tool.
Issue: "Input file does not exist"
Solution: Verify the file path is correct and the file exists
Issue: "Input file does not have a .py extension"
Solution: Ensure your input file ends with .py
Issue: "Invalid arguments provided"
Solution: Check the syntax - you must specify an obfuscation method (--bytecode, --lambda, or --hybrid)
Issue: Obfuscated file doesn't run
Solution: Ensure the original file runs without errors before obfuscating
- Discord: vihtoriax
- telegram: https://t.me/vihtoriadev