How do (not) I distribute my Python progz?

T

Tolga

Let's suppose that I have written a Python program and, of course, want
to show it to the world ;-)

So, do I have to distrubute my source code? Or is there a way to hide
my code?
 
P

Paul Rubin

Tolga said:
Let's suppose that I have written a Python program and, of course, want
to show it to the world ;-)

So, do I have to distrubute my source code? Or is there a way to hide
my code?

You're not really showing it to the world, if you hide the source.
 
S

Steven D'Aprano

Tolga said:
Let's suppose that I have written a Python program and, of course, want
to show it to the world ;-)

So, do I have to distrubute my source code? Or is there a way to hide
my code?

Why? Is there a problem with your source code? Are you
ashamed of it? Or trying to hide secret back-doors? Or
do you think that your "Hello World" program is worth
millions of dollars? *wink*

For many purposes, you can just distribute the .pyc
compiled byte-code. That will discourage the casual
user from reading the source code, but of course a
serious programmer will be able to disassemble the .pyc
code very easily.
 
B

Ben Sizer

Tolga said:
Let's suppose that I have written a Python program and, of course, want
to show it to the world ;-)

So, do I have to distrubute my source code? Or is there a way to hide
my code?

Suggested solutions to this in the past have including using Py2exe (or
something like it) to create single-file distributables (viewable with
a zip program, however), writing custom import hooks to decode
encrypted modules, and storing valuable data online. It might even be
possible to do some sort of RMI and store useful parts of your code
online, although this requires a network connection and a
latency-insensitive application, which are by no means universal.

You could also consider moving your sensitive code to a compiled C
module, perhaps using something like Pyrex to make it fairly easy.

Obviously you will want to decide whether it's worth the effort to do
all this, because most of the time it won't be.
 
J

Juergen Kareta

Hi Steven,
For many purposes, you can just distribute the .pyc compiled byte-code.
That will discourage the casual user from reading the source code, but
of course a serious programmer will be able to disassemble the .pyc code
very easily.

very easily ?

I tried it with my own code a year or two ago, and had some problems
(sorry don't remember all steps, but I think there was a tool called
disassemble ?). As I don't use a repository at the moment, I would need
it sometimes to disassemble older versions of my exe'd code. Could you
please give some hints, how I can get on ?

Thanks in advance
Jürgen
 
S

Steven D'Aprano

Hi Steven,


very easily ?

I tried it with my own code a year or two ago, and had some problems
(sorry don't remember all steps, but I think there was a tool called
disassemble ?). As I don't use a repository at the moment, I would need
it sometimes to disassemble older versions of my exe'd code. Could you
please give some hints, how I can get on ?

What makes you think I'm a serious programmer? *wink*

Try this:


py> import dis # the Python disassembler
py>
py> def f(x):
.... print x
.... return x+1
....
py> dis.dis(f)
2 0 LOAD_FAST 0 (x)
3 PRINT_ITEM
4 PRINT_NEWLINE

3 5 LOAD_FAST 0 (x)
8 LOAD_CONST 1 (1)
11 BINARY_ADD
12 RETURN_VALUE
13 LOAD_CONST 0 (None)
16 RETURN_VALUE


Python's byte-code is not exactly as easy to understand as native Python,
but it is still understandable. And I wonder, is there a program which
will try to generate Python code from the output of the disassembler?
 
J

Juergen Kareta

Hi Steven,

What makes you think I'm a serious programmer? *wink*

Ok, it's not a 'serious' investigation, but maybe it could be, that you
(sometimes) quote something usefull ;-)

Python's byte-code is not exactly as easy to understand as native Python,
but it is still understandable. And I wonder, is there a program which
will try to generate Python code from the output of the disassembler?

look at:
http://www.crazy-compilers.com/decompyle/

it's only a online service. But if it works, it would be nice to have
such a tool as standalone programm.

Thanks a lot.

regards,
Jürgen
 
P

Paul Boddie

Juergen said:
look at:
http://www.crazy-compilers.com/decompyle/

it's only a online service. But if it works, it would be nice to have
such a tool as standalone programm.

And the next search result for decompyle on Google is...

http://packages.debian.org/unstable/python/decompyle

Get the source package from there, or check out your favourite
distribution's package repository. Very useful for investigating and
revealing the embarrassing secrets of closed source software, I think.

Paul
 
J

Juergen Kareta

Hi Paul,

I had looked to the same link and downloaded the package. Maybe I'll
give it a try at the christmas holidays - hope so ;-)

Thanks
Jürgen
 
G

gene tani

Paul said:
And the next search result for decompyle on Google is...

http://packages.debian.org/unstable/python/decompyle

Get the source package from there, or check out your favourite
distribution's package repository. Very useful for investigating and
revealing the embarrassing secrets of closed source software, I think.

Paul

http://users.cs.cf.ac.uk/J.P.Giddy/python/decompiler/decompiler.html
http://www.logilab.org/projects/pyreverse/
http://docs.python.org/lib/module-dis.html
http://docs.python.org/lib/bytecodes.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,274
Messages
2,571,366
Members
48,055
Latest member
RacheleCar

Latest Threads

Top