Is it possible to protect python source code by compiling it to .pyc or .pyo?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Jan 17 00:11:18 EST 2014


On Thu, 16 Jan 2014 16:58:48 -0800, Sam wrote:

> I would like to protect my python source code. It need not be foolproof
> as long as it adds inconvenience to pirates.

What makes you think that "pirates" will be the least bit interested in 
your code? No offence intended, I'm sure you worked really, really hard 
to write it, but the internet has hundreds of gigabytes of free and open 
source software which is easily and legally available, not to mention 
easily available (legally or not) non-free software at a relatively cheap 
price. Chances are that your biggest problem will not be piracy, but 
getting anyone to care or even notice that your program exists.


> Is it possible to protect python source code by compiling it to .pyc or
> .pyo? Does .pyo offer better protection?

Compiling to .pyc or .pyo will not give any protection from software 
piracy, since they can just copy the .pyc or .pyo file. It will give a 
tiny bit of protection from people reading your code, but any competent 
Python programmer ought to be able to use the dis module to read the byte 
code.

Perhaps if you explain what your program is, and why you think it needs 
protection, we can give you some concrete advice.



-- 
Steven



More information about the Python-list mailing list