I am developing a paid application in Python. I do not want the users to see the source code or decompile it. How can I accomplish this task of hiding the source code from the user, but running the code perfectly with the same performance?
-
Reverse engineering and disassembly are skills many people have. Plus there are tools to do this for them. If your product has enough value or is just interesting, someone will do this and publish their work. If your product value is only the source code, you are fighting a losing battle. Source code obfuscation just makes the task harder, but not by much. Back in the day, we would reverse engineer Windows, which is much harder than a Python program. Another tip, do not use any of the Python libraries, those are already open source and provide 90%+ of what someone needs to break your code.John Hanley– John Hanley2022-12-02 01:19:37 +00:00Commented Dec 2, 2022 at 1:19
3 Answers
You may distribute the compiled .pyc files which is a byte code that the Python interpreter compiles your .py files to.
More info on this found here on stackoverflow. How to compile all your project files.
This will somewhat hide your actual code into bytecode, but it can be disassembled. To prevent from disassembling you need to use obfuscation. Pyarmor might be something you're looking for.
Comments
The best way would be to turn your python code into an executable file.
When u take a look here, there is a nice Tutorial on how to do it:
- Install pyinstall via
pip3 install pyinstaller - Pack your excecutable with
pyinstaller main.py
There is a lot of options to tweak the output of your application, the docs can be found under https://pyinstaller.org/en/stable/
4 Comments
.py script into .exe, but the actual .py can be easily recovered. This is a solution to make your script portable and run on different machines that do not have python installed. It does not provide any code protection though..exe could be opened with 7-zip. Let me try now.