Distributing closed source modules

Fuzzyman fuzzyman at gmail.com
Fri Mar 25 04:21:35 EST 2005


Dave Brueck wrote:
> Jiri Barton wrote:
[snip..]

Hello Dave,

>
> Protecting code in any language is pretty tough and/or futile, but
you can
> Google the archives if you're interested in reading more on that.
>

It's certainly something lot's of people are interested in. I guess it
depends who your audience is. If ytour code isn't for *mass*
distribution - the chances of people putting a lot of effort into
breaking it are greatly reduced. I don't htink it's necessarily futile.

> Anyway, you can create a module on the fly like this (untested):
>
> import new, sys
> name = 'MyModule'
> m = sys.modules[name] = new.module(name)
> exec codeStr in m.__dict__
>
> where codeStr is a string that contains the source code of your
module (e.g.
> from file('somemodule.py').read() ).
>

This is one of the better solutions I've seen. (Probably because it's
*not* very complex). The stored modules can be well encrypted.
Obviously the decryption code will be in the main code - but I guess it
can be obfuscated pretty well.

I like it.

Regards,

Fuzzy
http://www.voidspace.org.uk/python

> You can combine the above with whatever mechanism you come up with
for
> distributing the code itself. You could store it in an encrypted
archive file,
> you could download it on the fly from a remote server over a secure
connection, etc.
> 
> -Dave




More information about the Python-list mailing list