Is it possible to protect python source code by compiling it to .pyc or .pyo?
Ned Batchelder
ned at nedbatchelder.com
Thu Jan 16 20:07:04 EST 2014
On 1/16/14 7:58 PM, Sam wrote:
> I would like to protect my python source code. It need not be foolproof as long as it adds inconvenience to pirates.
>
> Is it possible to protect python source code by compiling it to .pyc or .pyo? Does .pyo offer better protection?
>
First, .pyc and .pyo are nearly identical: they are bytecode. The only
difference is that .pyo has been "optimized", which in this case simply
means that the docstrings and asserts are gone. It is not difficult to
see what a Python program does by looking at the bytecode, and the
standard library includes the dis module for disassembling it.
How to protect your code depends an awful lot on what kinds of secrets
are in the code, and how valuable those secrets are, and therefore how
hard someone will work to get at them.
--
Ned Batchelder, http://nedbatchelder.com
More information about the Python-list
mailing list