I've been using python for years, but I have little experience with python web programming. I'd like to create a very simple web service that exposes some functionality from an existing python script for use within my company. It will likely return the results in csv. What's the quickest way to get something up? If it affects your suggestion, I will likely be adding more functionality to this, down the road.
This question is related to
python
web-services
If you mean "web service" in SOAP/WSDL sense, you might want to look at Generating a WSDL using Python and SOAPpy
maybe Twisted http://twistedmatrix.com/trac/
The simplest way to get a Python script online is to use CGI:
#!/usr/bin/python
print "Content-type: text/html"
print
print "<p>Hello world.</p>"
Put that code in a script that lives in your web server CGI directory, make it executable, and run it. The cgi
module has a number of useful utilities when you need to accept parameters from the user.
Raw CGI is kind of a pain, Django is kind of heavyweight. There are a number of simpler, lighter frameworks about, e.g. CherryPy. It's worth looking around a bit.
Life is simple if you get a good web framework. Web services in Django are easy. Define your model, write view functions that return your CSV documents. Skip the templates.
If you mean with "Web Service" something accessed by other Programms SimpleXMLRPCServer might be right for you. It is included with every Python install since Version 2.2.
For Simple human accessible things I usually use Pythons SimpleHTTPServer which also comes with every install. Obviously you also could access SimpleHTTPServer by client programs.
Raw CGI is kind of a pain, Django is kind of heavyweight. There are a number of simpler, lighter frameworks about, e.g. CherryPy. It's worth looking around a bit.
Life is simple if you get a good web framework. Web services in Django are easy. Define your model, write view functions that return your CSV documents. Skip the templates.
web.py is probably the simplest web framework out there. "Bare" CGI is simpler, but you're completely on your own when it comes to making a service that actually does something.
"Hello, World!" according to web.py isn't much longer than an bare CGI version, but it adds URL mapping, HTTP command distinction, and query parameter parsing for free:
import web
urls = (
'/(.*)', 'hello'
)
app = web.application(urls, globals())
class hello:
def GET(self, name):
if not name:
name = 'world'
return 'Hello, ' + name + '!'
if __name__ == "__main__":
app.run()
maybe Twisted http://twistedmatrix.com/trac/
Look at the WSGI reference implementation. You already have it in your Python libraries. It's quite simple.
If you mean with "Web Service" something accessed by other Programms SimpleXMLRPCServer might be right for you. It is included with every Python install since Version 2.2.
For Simple human accessible things I usually use Pythons SimpleHTTPServer which also comes with every install. Obviously you also could access SimpleHTTPServer by client programs.
If you mean "web service" in SOAP/WSDL sense, you might want to look at Generating a WSDL using Python and SOAPpy
The simplest way to get a Python script online is to use CGI:
#!/usr/bin/python
print "Content-type: text/html"
print
print "<p>Hello world.</p>"
Put that code in a script that lives in your web server CGI directory, make it executable, and run it. The cgi
module has a number of useful utilities when you need to accept parameters from the user.
If you mean "web service" in SOAP/WSDL sense, you might want to look at Generating a WSDL using Python and SOAPpy
Raw CGI is kind of a pain, Django is kind of heavyweight. There are a number of simpler, lighter frameworks about, e.g. CherryPy. It's worth looking around a bit.
If you mean with "Web Service" something accessed by other Programms SimpleXMLRPCServer might be right for you. It is included with every Python install since Version 2.2.
For Simple human accessible things I usually use Pythons SimpleHTTPServer which also comes with every install. Obviously you also could access SimpleHTTPServer by client programs.
Life is simple if you get a good web framework. Web services in Django are easy. Define your model, write view functions that return your CSV documents. Skip the templates.
web.py is probably the simplest web framework out there. "Bare" CGI is simpler, but you're completely on your own when it comes to making a service that actually does something.
"Hello, World!" according to web.py isn't much longer than an bare CGI version, but it adds URL mapping, HTTP command distinction, and query parameter parsing for free:
import web
urls = (
'/(.*)', 'hello'
)
app = web.application(urls, globals())
class hello:
def GET(self, name):
if not name:
name = 'world'
return 'Hello, ' + name + '!'
if __name__ == "__main__":
app.run()
Look at the WSGI reference implementation. You already have it in your Python libraries. It's quite simple.
Raw CGI is kind of a pain, Django is kind of heavyweight. There are a number of simpler, lighter frameworks about, e.g. CherryPy. It's worth looking around a bit.
If you mean with "Web Service" something accessed by other Programms SimpleXMLRPCServer might be right for you. It is included with every Python install since Version 2.2.
For Simple human accessible things I usually use Pythons SimpleHTTPServer which also comes with every install. Obviously you also could access SimpleHTTPServer by client programs.
Life is simple if you get a good web framework. Web services in Django are easy. Define your model, write view functions that return your CSV documents. Skip the templates.
maybe Twisted http://twistedmatrix.com/trac/
The simplest way to get a Python script online is to use CGI:
#!/usr/bin/python
print "Content-type: text/html"
print
print "<p>Hello world.</p>"
Put that code in a script that lives in your web server CGI directory, make it executable, and run it. The cgi
module has a number of useful utilities when you need to accept parameters from the user.
If you mean "web service" in SOAP/WSDL sense, you might want to look at Generating a WSDL using Python and SOAPpy
Look at the WSGI reference implementation. You already have it in your Python libraries. It's quite simple.
maybe Twisted http://twistedmatrix.com/trac/
The simplest way to get a Python script online is to use CGI:
#!/usr/bin/python
print "Content-type: text/html"
print
print "<p>Hello world.</p>"
Put that code in a script that lives in your web server CGI directory, make it executable, and run it. The cgi
module has a number of useful utilities when you need to accept parameters from the user.
Source: Stackoverflow.com