Obscuring Python source from end users

Dan Stromberg drsalists at gmail.com
Thu Oct 2 00:06:00 CEST 2014

On Mon, Sep 29, 2014 at 4:47 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> norman.ives at gmail.com wrote:
>> Hello list
>> Python 3.4 applies.
>> I have a project that involves distributing Python code to users in an
>> organisation. Users do not interact directly with the Python code; they
>> only know this project as an Excel add-in.
>> Now, internal audit takes exception in some cases if users are able to see
>> the source code.
> You have my sympathy.

Actually, I don't think this is that bad.  Companies have rules; one
simply has to learn to live with this or suffer greatly.  Some rules
are worth fighting, but this probably isn't one of them.

>> So I'm wondering if anyone has clever suggestions in this regard...
> Yes. Distribute the pyc files only.

Yes, this is the way it's usually done.  Supposedly Microsoft did this
for a while, after acquiring some Python software.  In the Python 3.4
case, the pyc's should be in the __pycache__ subdirectory.

Another option would be to convert to Cython and compile (not as bad
as it sounds).  But __pycache__/*.pyc would probably be easier.

More information about the Python-list mailing list