views:

229

answers:

4

Hi,

I wrote a web service API which services REST requests in php. It didn't take much time to actually setup this on apache. But, I am more comfortable writing python code rather than php code. Can python be used as a server-side scripting language like php? What changes are necessary to make it work with apache?

Thanks Bala Mudiam

+3  A: 

For a REST full API I would suggest that you take a look at Tornado. It's what Facebook uses. It's fast, efficient and easy to work with (written i Python). You may use nginx as a proxy in front of it to server static content and allow more Tornado services for scaling.

MyGGaN
+1 Looks like you said "Tomado" which in spanish is "Drunk" lol
OscarRyz
Hehe, nice! I'll remember that one ;)
MyGGaN
Does Tornado provide any special facilities for implementing REST-ful APIs? I agree that it is a nice piece of technology but isn't it more of a web server in its own right? What comparisons can be made between say something like django-piston or restish?
Brian Luft
It sure is a webserver of its own. Its single threaded/epoll design makes it suitable for an API server since it can CPU efficiently handle lots of requests/second. I have used django before but not django-piston nor restish. I've found it fulfilling all my needs and I don't regret that I moved from django to Tornado. It works nicer with templates too. For performances you can follow this link: http://www.tornadoweb.org/documentation#performance
MyGGaN
+1  A: 

Yes Python can be used as server-side language (as well as Perl, Ruby or even C/C++). Just use mod_python for Apache http://www.modpython.org/

doc
+2  A: 

Python is a very capable server-side language. Large sites (such as AG Interactive) use Python for server-side programming and have had great results. mod_python and mod_wsgi are 2 popular modules for Apache that allow you to serve Python.

Kaleb Brasee
I have heard a lot of chatter that mod_python lags in performance compared to mod_wsgi. Could it have something to do with the fact that mod_python hasn't been updated in almost 2 years?
jathanism
That's possible, I noticed that it's been a while since the last update. AG just wrote their own Apache python mod, but that's a lot of work.
Kaleb Brasee
The mod_python module is slower at basic handling because it implements parts of that mechanism in Python code and has an elaborate script importing system whereas mod_wsgi is all in C code interacting direct with C APIs of Python and has only absolute minimum script importing mechanism required. Nothing to do with mod_python not being updated for a number of years.
Graham Dumpleton
Also, seems that the mod_python project is now officially dead.
hyperboreean
+1  A: 

I'll dare to say that mod_wsgi is probably closer to the de-facto choice (vs. mod_python) if you're stuck with Apache as your web server these days. One benefit is that you'll find a wide range of active frameworks and libraries that are WSGI compatible. Please don't read too deeply into "framework" - some things I'd lump in there are quite minimal, providing a few nice conveniences on top of raw WSGI to help you organize your code. Imagining that you're not looking to invest into a web framework itself just to get a REST interface up, you might check out restish as an option.

Brian Luft