Advice on converting a python program to a web app?
September 19, 2012 5:04 AM   Subscribe

Hi I have programmed on eclipse, a reasonably straightforward program in Python 2.7 that applies image filters to user selected images e.g. by turning them to sepia, black & white, negative, etc. It uses Tkinter for the graphics user interface and the program functions ok. However, I was thinking about how to turn this into a web app. So to transfer this to an Amazon cloud server, I understand that for the client side user interface I would need to convert the program by adding html and javascript to the client side while python handles the server side? Does anyone know of any tutorials or other resources that are particularly good at covering web apps like this using python, html and javascript?
posted by conrad101 to Computers & Internet (3 answers total) 3 users marked this as a favorite
Python web deployment isn't hard, but its much more dificult than say PHP deployment and there are a lot of competing ways to do it.

Presumably you have a class or function that takes an image file writes another.

Your best bet is to use a micro framework like flask or bottle to handle the upload, pass it off to your class and write it to a public static directory. These frameworks will give you what you need to handle requests, uploaded files, serve templates to the user, etc.

Follow the simple tutorials and use a the development server until you get something working, then deploy it on amazon. A basic set of steps might be:

Log onto your ec2 instance
Install python
Install nginx
Install something like gunicorn as a wsgi server.

Put your flask project on the server

Configure everything (there are tutorials depending on what technologies you decide to use, here's one

You should probably use virtualenv, but it can be daunting and add some configuration steps, so maybe skip it for now if you're new to python deployment.

If your image processing takes a long time and you expect a good amount of traffic, you're going to want a way to do that processing outside of the web request. There are many ways to do this, Celery is one.
posted by miniape at 5:56 AM on September 19, 2012

Python web deployment isn't hard, but its much more dificult than say PHP deployment and there are a lot of competing ways to do it.

Deploying Flask to Heroku is about the easiest thing I've ever done, web-development-wise, and I'm not very good at web development. Flask is lovely to build little webapps in compared to PHP. Heroku is free for a small webapp, too (but gets quite expensive once you start adding background processes etc).
posted by BungaDunga at 7:09 AM on September 19, 2012

If you expect any volume, look into using an offline task queue for those image operations now. Run the part of your python script on a loop or under cron in the background, pulling jobs from amazon's simple queue service (SQS) and putting the results someplace useful. Then you can use php or flask or whatever for the web-facing bits and it won't matter.
posted by migurski at 11:10 AM on September 20, 2012

« Older Basic steps to put some zoom in my Zumba?   |   I think I inhaled a bit of a melting plastic bag... Newer »
This thread is closed to new comments.