473,703 Members | 3,307 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Distributing closed source modules

Hi,

I'd like to be able to distribute some python modules of my system (plugins)
without the source. So far, I have done this by including only the *.pyc
files. However, I have recently found they are platform dependent and
python version dependent.

This approach has been very convenient because I don't have to mess up with
__import__ and the like - which seem to be kind of a pain when inter-module
dependencies are introduced.

Can some one point me in another direction of protecting the code? I know
and this whole thing just does not sound right to me either but I am forced
to do so.

TIA, jbar
Jul 18 '05 #1
5 1723
Jiri Barton wrote:
I'd like to be able to distribute some python modules of my system (plugins)
without the source. So far, I have done this by including only the *.pyc
files. However, I have recently found they are platform dependent and
python version dependent.

This approach has been very convenient because I don't have to mess up with
__import__ and the like - which seem to be kind of a pain when inter-module
dependencies are introduced.

Can some one point me in another direction of protecting the code? I know
and this whole thing just does not sound right to me either but I am forced
to do so.


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.

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('somemodul e.py').read() ).

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
Jul 18 '05 #2

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('somemodul e.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


Jul 18 '05 #3
Fuzzyman wrote:
Dave Brueck wrote:
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.


By "futile" I meant that, if the code ends up running on a user's machine, then
a sufficiently motivated person could crack it wide open, regardless of
implementation language - the only way to truly protect the code is to never let
it out of your hands (i.e. it's accessible just via a web service).

-Dave
Jul 18 '05 #4

Dave Brueck wrote:
Fuzzyman wrote:
Dave Brueck wrote:
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.
By "futile" I meant that, if the code ends up running on a user's machine, then a sufficiently motivated person could crack it wide open, regardless of implementation language - the only way to truly protect the code is to never let it out of your hands (i.e. it's accessible just via a web service).

Hello Dave,

I understand what you are saying - using hte word 'futilew' implies
that code is *likely* to be broken, not that it is *theoretically
possible* for it to be broken. If code has a small user base it is
probable that there is plenty that can be done to make breaking the
code a lot harder. There are also legitimate reasons why someone would
want to do this. 'Futile' is definitely a misleading response :-)3

It's a question that often comes up on comp.lang.pytho n - and the reply
is often "don't bother, it's not possible - and why do you want to do
that anyway". This is a response that is likely to turn people towards
other languages....

Best Regards,

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


Jul 18 '05 #5
Fuzzyman wrote:
Dave Brueck wrote:
By "futile" I meant that, if the code ends up running on a user's
machine, then
a sufficiently motivated person could crack it wide open, regardless
of
implementatio n language - the only way to truly protect the code is
to never let
it out of your hands (i.e. it's accessible just via a web service).

I understand what you are saying - using hte word 'futilew' implies
that code is *likely* to be broken, not that it is *theoretically
possible* for it to be broken. If code has a small user base it is
probable that there is plenty that can be done to make breaking the
code a lot harder. There are also legitimate reasons why someone would
want to do this. 'Futile' is definitely a misleading response :-)3
Not really. For all practical purposes, shipping .pyc files is probably
sufficient for most of the software out there: (1) it's a high enough "fence"
for almost all users, (2) for most programs, getting the source code and being
able to do something with it are two very different things, and (3) for most
programs, there really is no proprietary magic worth protecting.

So, when somebody says it's not good enough, and they need something better, I
have to admit I'm initially skeptical of their perceived need for "better"
protection of the source code (there _are_ some cases where it should be
protected, but they are much less common than people seem to think). One of two
things is probably true in these cases:

1) The value of the source code is overestimated - yes, it's a nice program, but
there's not really anything in there to warrant the higher
development/deployment/debugging costs associated with more security. As such,
nobody is really going to care enough to crack the code. And if anybody does,
it's unlikely that they'll actually do anything with the code. Thus, the effort
to secure the code more is futile - it's ineffective because the effort will
never provide any benefit.

OR

2) The code really does have some innovative, proprietary algorithm, like a
video codec with wildly improved compression (that for some reason you've
implemented in pure Python ;-) ). If the value of the code is really high, then
no amount of security is going to prevent people from getting at it - trying to
protect your code is futile because no matter how high a wall you create,
sufficiently determined people will climb over it. Plus, protecting the source
code may be the least of your worries (if they're willing to steal your code,
they may just as well be willing to use your library illegally, etc.).
It's a question that often comes up on comp.lang.pytho n - and the reply
is often "don't bother, it's not possible - and why do you want to do
that anyway". This is a response that is likely to turn people towards
other languages....


Perhaps the response could be framed better, but at the same time it _is_ a
pretty honest response, and maybe Python really _isn't_ the language for such
people. It's just like people who ask for curly braces - Python is not the
language for them. So if I asked for braces, a lot of the c.l.py responses would
be geared towards helping me understand that they aren't really needed, but if I
insist that I have to have them, then maybe Python isn't for me. :)

So, when the question comes up, I don't mind offering some suggestions, but the
suggestions will always include the disclaimer that it's probably a waste of
time & effort - IMO leaving that part out would be misleading.

-Dave
Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
5909
by: Milos Prudek | last post by:
Hi, is it technically possible to distribute a python project as a closed source, i.e. encrypted? I believe that *.pyc files do not work without *.py sources... and they can be easily decompiled. -- Milos Prudek
14
1875
by: Phillip Mills | last post by:
I've learned enough of the Python language to be mildly dangerous and have used it in a few personal projects. All my development of commercial (or production) products over the past dozen years have been done with C++ or Java. For a program I'm planning -- to begin during the summer -- having an interpreter as part of the application would be very desirable to allow sophisticated users to provide their own extensions. Java would be...
6
1826
by: Jason | last post by:
A non-python programming friend of mine has said that any programs made with Python must be distributed with, or an alternative link, to the source of the program. Is this true?
2
2666
by: RickMuller | last post by:
I really appreciate the ease that the distutils make distributing Python modules. However, I have a question about using them to distribute non-Python (i.e. text) data files that support Python modules. Currently when I have data of this type, I parse it into python objects and make a python module from it. In other words, given a data file like % cat grocery_list.txt eggs spam
9
2030
by: alf | last post by:
Hi, I have a small app which consist of a few .py files. Is there any way to distribute it in jar like fashion as a single file I can just run python on. I obviously look for platform independent solution. Thx in advance, A.
11
4013
by: Tina I | last post by:
Hi list, Is there a preferred way to distribute programs that depends on third party modules like PyQt, Beautifulsoup etc? I have used setuptools and just having the setup script check for the existence of the required modules. If they're not found I have it exit with a message that it need this or that installed. But this is not very convenient for the end user and I have got a few complaints about it. Am I missing something in...
1
1410
by: PurpleServerMonkey | last post by:
Working on a rather large open source python application that I want to release for Linux and BSD and was wondering what methods others are using to distribute large and complex applications. Setuptools and friends seem to be focused on distributing modules, I'm at the other end of the scale where I want to distribute an entire application so that an Administrator can run a single install and have a fully operational product. A key...
9
1506
by: eliben | last post by:
Hello, I'm getting into Python now after years of Perl, and as part of my research I must understand how to do some common tasks I need. I have a bunch of Windows PCs at work to which I want to distribute an application I've developed on my PC. All these PCs have Python 2.5 installed. If my application contains only code I've developed, I simply zip its
5
2607
by: Joe Strout | last post by:
We have a client who's paranoid about distributing the Python source to his commercial app. Is there some way I can distribute and use just the .pyc files, so as to not give away the source? Thanks, - Joe
0
8662
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9243
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8956
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7853
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5922
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2434
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2057
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.