Can I deploy Python .pyc files only to Google App Engine?

2.8k views Asked by At

I'm working on a project utilizing Django on Google App Engine. I've been asked if some of the code can be deployed as compiled only.

So I guess the question is can I upload a .pyc file only that contains the piece of code in question? I've done a basic test with a views.pyc file in an application and things don't work. Is there some configuration or other that I can set to allow Google App Engine to just use the .pyc files?

3

There are 3 answers

0
mgiuca On BEST ANSWER

I realise you couldn't do this when you asked this question, but you can now, if you use Python 2.7. See Sandboxing in Python 2.7:

You can upload and use .pyc, but not in combination with .py files. You can upload zip files containing .py or .pyc files (or a combination).

0
Senthil Kumaran On

Why would you want to do that in the first place? Because your .py files are uploaded to Google infrastructure and can be seen only if you explicitly give permissions. But yes, there is no reason as why uploading only .pyc files should not work. If you try it, in your dev environment, you will find it working just as BaseHTTPServer can take python compiled modules as handlers. Also, recent GAE supports automatic precompilation for python files, which means that as soon as you update your application, the python files can precompiled and served. So, you might have to play with --no_precompilation during appcfg.py upload if there was any expectation to check for .py files at the app engine end.

3
Nick Johnson On

No, you can't - you can only upload sourcecode. There's no good reason to do this, though: your code will be bytecode-compiled on the servers when needed, and nobody is able to access your code in any case.