How to secure python script?

I have been using UnrealEnginePython plugin for using python in runtime.

I have some python scripts from which i made pyc files for securing my code. But pyc is not recompiled easily.

My question is how python code keeps security in professional project?

Iā€™m not sure how UnrealEnginePython plugin packages python scripts, but note that pyc files can be decompibled pretty trivially revealing semi-human readable code. One thing you can do to apply some simple obfuscation to your code is to compile with the -OO option which will apply basic optimizations as well as stripping comments and docstrings from your compiled files.

python -OO py_compile <your_program.py>

However this only applies extremely basic obfuscation and will not prevent your code from being decompiled. There are other techniques for obfuscating python code encoding as base64 or using a utility like pyarmor to obfuscate the bytcode.

thank you so much and sorry for the late response. Seems like that plugin could only work on pyc files but pyc can easily be decompiled. By using cython, i created pyd file of python module. I searched a bit. So far pyd file is very very hard to decompile or not possible (not sure, but it is the safest i could find). Since plugin could not work on pyd, i made a normal pyc file calling the module which is pyd file. Thats when there was no problem, plugin took it and it worked and i also could save my important code putting them in a module of pyd file. Of course, i aint totally sure if it is the best solution or not but so far it is where i am now.

1 Like

Sounds like a good solution. I believe that a determined adversary could still decompile the pyd and reverse engineer the decompiled C code from there; but this would be quite difficult, and unless your code is top secret it is probably good enough and will definitely prevent casual plagiarism.

what about not, i counter this problem as well