views:

66

answers:

2

Dear all,

I am new to the world of IT business (serious) development but I have in mind a business idea and still trying to vizualize how the overall infrastructure should work.

I have done some few research for a good technology to deliver the solution. I am very inclined to use Python, MySql, Django (Apache) on the server side and some RIA on the client side (probably Flex) as I need some advanced visualization capabilities (especially after seeing the FLARE project).

The application requires some "heaving lifting" on the numerical / statistical side and integrating R with Python (RPy2) + other like NumPy seems to be ideal.

The thing i cannot get so far (certainly because i am a newbie) is the following:

Can Django (one way or the other) execute an (external) python script / program which contain reference to the extra libraries (NumPy ...)?

ex: user triggers an action to perform a statistical analysis, Django receives the request and should run some python code (using R, NumPy...) which uses the data in the database and store the results back in the DB. Django accesses the DB data and send it back to the client app to be displayed.

Is this the right logic or am i completely off path?

Many thanks in advance for your expertise.

+1  A: 

If you can install it on the server and import it into python, then you can use it in python and hence Django.

That is to say, if

import foo

works, then so does

import foo

foo.bar(fobaz)

assuming that it would work without Django. Also, if you were to try to do something that sent HTTP headers or responses outside of Django, you might run into problems but numerical packages wont do anything like that.

aaronasterling
+5  A: 

Django is a Python program. And like any other Python program it will be able to access other Python scripts/modules. The question then, is how to execute the script. If your script explicitly defines a main (or another starting point) function then you can merely import it as you would a module and call the main.

For instance:

# my custom script. Located in my_script.py
# lots of functions

def main():
    # call functions in sequence.

# my django view.
from myscript import main as script_main
script_main()

If you'd rather execute as if from the command line then look at the subprocess module. If you want to run it asynchronously then something like Celery might be what you are looking for.

Manoj Govindan