Would compiling with cython work with a python 3.4 Django app, or could it be made to work without a huge amount of effort?

This answer - https://stackoverflow.com/a/7347168/805141 - to a question about protecting python code prompted me to ask this question.

A similar question has been asked previously but with regards to improving performance: Using Cython with Django. Does it make sense?

  • You understand that Cython is not for packages, right? – Ignacio Vazquez-Abrams Sep 15 '15 at 4:44
  • I did not. Is there some workaround to that? – Daniel Sep 15 '15 at 12:01
  • 1
    Make the app more difficult to reverse engineer for clients who want to run the app server in their own data center, using the idea of stackoverflow.com/a/7347168/805141 – Daniel Sep 16 '15 at 22:00
  • 2
    @Daniel "You won't gain much" was mostly about performance. Guessing at difficultly to reverse engineer: the code generated will have a lot of Python API calls, and have a lot of strings (as attribute names, and because this kind of web app deals with a lot of string) which might make it comparatively easy to reverse engineer for someone who's really committed. However, it will be harder than from Python code. It might not be a lot harder than reverse engineering ".pyc" bytecode files. This is all a bit of a guess though. – DavidW Sep 17 '15 at 6:51
  • 3
    I can tell you with good certainty that it will at least make the app much more difficult to maintain. I'd say do not compile the whole code, only parts of it - only calculations, that you could isolate as standard (no Django) Python functions. – JulienD Sep 18 '15 at 18:08

Yes, we have done it. But it point of consistent pain.

We make a commercial product called InProd which is installed on the customer premise to manage their Genesys power contact center. The core of the application is written in Django and we wanted to protect (limit) the code from inspection.

There is a speed improvement from running in native python but it is not a considerable difference. The improvement depends on the type of task, sometimes up to 30% sometimes minimal.

We run into issues from time to time where something works in Python but then it does not in Cython. I would not recommend this path unless you have a really good motivation.

Currently version runs on Python 3.5 with Django 1.11

  • can you give exact example commandline and methodology to compile a dummy hello world django project using cython, and then run it? – zaxebo1 Aug 30 '18 at 4:07

Your Answer

