By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,923 Members | 1,279 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,923 IT Pros & Developers. It's quick & easy.

WSGI - How Does It Affect Me?

P: n/a
So I keep hearing more and more about this WSGI stuff, and honestly I
still don't understand what it is exactly and how it differs from CGI
in the fundamentals (Trying to research this on the web now)

What I'm most confused about is how it affects me. I've been writing
small CGI programs in Python for a while now whenever I have a need
for a web program. Is CGI now considered "Bad"? I've just always
found it easier to write something quickly with the CGI library than
to learn a framework and fool with installing it and making sure my
web host supports it.

Should I switch from CGI to WSGI? What does that even mean? What is
the equivalent of a quick CGI script in WSGI, or do I have to use a
framework even for that? What do I do if frameworks don't meet my
needs and I don't have a desire to program my own?

Examples of how frameworks don't meet my needs sometimes:
1. Working with SQL Server (Most frameworks seem to at least make it extra work)
2. Need web app to get data from other programs via API (eg QuickBooks)
Can any web framework work happily with win32 extensions?
3. Using IIS at all for that matter, does WSGI work on IIS, do any frameworks?

Hope this question isn't too confusing or rambling, or it hasn't been
covered before. (it's hard to frame these questions as search terms
at least for me)

-Greg Pinero
Oct 8 '06 #1
Share this Question
Share on Google+
11 Replies


P: n/a
Gregory Piñero enlightened us with:
So I keep hearing more and more about this WSGI stuff, and honestly I
still don't understand what it is exactly
AFAIK it's a standard for web frameworks. In such a framework, you
receive a 'request' object, and return a 'response' object. If I'm
correct, the WSGI describes things like the method and property names
on those objects etc.
What I'm most confused about is how it affects me. I've been writing
small CGI programs in Python for a while now whenever I have a need
for a web program. Is CGI now considered "Bad"?
I've never considered CGI bad, but I do consider it to be a hassle to
make anything non-trivial. If you want a website with template engine,
web-based database admin, and automatic form generation and
validation, it's easier to use an existing web framework.
What is the equivalent of a quick CGI script in WSGI, or do I have
to use a framework even for that?
I'd simply use CGI for that.
What do I do if frameworks don't meet my needs and I don't have a
desire to program my own?
That depends on the needs I guess.
Examples of how frameworks don't meet my needs sometimes:
1. Working with SQL Server (Most frameworks seem to at least make it
extra work)
I've never seen a framework that's unable to work with an SQL server.
2. Need web app to get data from other programs via API (eg
QuickBooks) Can any web framework work happily with win32
extensions?
You can use any module you want in a Django view, including win32.
3. Using IIS at all for that matter, does WSGI work on IIS, do any
frameworks?
Why would you want to use that monstrosity?

Sybren
--
Sybren Stüvel
Stüvel IT - http://www.stuvel.eu/
Oct 8 '06 #2

P: n/a
On 10/8/06, Sybren Stuvel <sy*******@yourthirdtower.com.imaginationwrote:
3. Using IIS at all for that matter, does WSGI work on IIS, do any
frameworks?

Why would you want to use that monstrosity?
Two words: "contractual obligation"

-- Theerasak
Oct 8 '06 #3

P: n/a
Theerasak Photha enlightened us with:
3. Using IIS [...]

Why would you want to use that monstrosity?

Two words: "contractual obligation"
That doesn't answer the question. It only makes me ask it to someone
else, namely the parties involved in creating the contract.

Sybren
--
Sybren Stüvel
Stüvel IT - http://www.stuvel.eu/
Oct 8 '06 #4

P: n/a
So I keep hearing more and more about this WSGI stuff, and honestly I
still don't understand what it is exactly and how it differs from CGI
in the fundamentals (Trying to research this on the web now)

What I'm most confused about is how it affects me. I've been writing
small CGI programs in Python for a while now whenever I have a need
for a web program. Is CGI now considered "Bad"?
Well, mostly "yes" :)
I've just always
found it easier to write something quickly with the CGI library than
to learn a framework and fool with installing it and making sure my
web host supports it.

Should I switch from CGI to WSGI? What does that even mean? What is
the equivalent of a quick CGI script in WSGI, or do I have to use a
framework even for that? What do I do if frameworks don't meet my
needs and I don't have a desire to program my own?
def simple_app(environ, start_response):
"""Simplest possible application object"""
status = '200 OK'
response_headers = [('Content-type','text/plain')]
start_response(status, response_headers)
return ['Hello world!\n']

To serve it as a CGI just:
from wsgiref.handlers import CGIHandler
CGIHandler().run(simple_app)

It's not that complicated isn't it... and later you might want to move to
mod_python, scgi or fastcgi or IIS... you will not have to modify
simple_app a bit.

OR... you might want to use the EvalException middleware... just wrap your
simple_app like this:
app = EvalException(simple_app)

(well, due to it's simplicity EvalException can only work in single-process,
long running WSGI servers like not in CGI) so:

s = wsgiref.simple_server.make_server('',8080, app)
s.server_forever()

More info at
http://wsgi.org/wsgi/Learn_WSGI
3. Using IIS at all for that matter, does WSGI work on IIS, do any
frameworks?
There's an IIS server gateway (WSGI server) but you can always run WSGI
applications with CGI, as seen above.

--
damjan
Oct 8 '06 #5

P: n/a
Gregory Piñero wrote:
Examples of how frameworks don't meet my needs sometimes:
1. Working with SQL Server (Most frameworks seem to at least make it extra work)
I don't know about "most frameworks", but there are certainly some that
work with SQL Server. My Dejavu ORM does SQL Server and MS Access
(among others): http://projects.amor.org/dejavu
2. Need web app to get data from other programs via API (eg QuickBooks)
Can any web framework work happily with win32 extensions?
I use win32 extensions quite happily with Dejavu (and CherryPy). I've
got a similar situation with The Raiser's Edge from Blackbaud: reads
are done via SQL Server (for speed) and writes are done via their COM
interfaces. In fact, we were looking at using Quickbooks for that but
made our decision about 2 months before Intuit announced their first
open API. :/
3. Using IIS at all for that matter, does WSGI work on IIS, do any frameworks?
They can with some work. When I first started coding for/with CherryPy,
I wrote a WSGI adapter for ASP:
http://projects.amor.org/misc/wiki/ASPGateway (I've since switched to
Apache2 on Windows, but that code should still work). I believe there's
a WSGI-ISAPI adapter somewhere out there... last time I looked, it
didn't do SSL or multithreading yet.
Robert Brewer
System Architect
Amor Ministries
fu******@amor.org

Oct 8 '06 #6

P: n/a
Trying to research this on the web now

Lots of articles now appearing summarising WSGI ...

For definitive reference:

<http://www.python.org/dev/peps/pep-0333/[0]

Overview:

<http://www.xml.com/lpt/a/1674 [1] and
<http://www.xml.com/lpt/a/1675 [2]

Reference
[0] python.org, 'Python Web Server Gateway Interface v1.0, Phillip J.
Eby'
<http://www.python.org/dev/peps/pep-0333/>
[Accessed Monday, 9 October 2006]

[1] xml.com, ''Introducing WSGI: Python's Secret Web Weapon, James
Gardner'
<http://www.xml.com/lpt/a/1674>
[Accessed Monday, 9 October 2006]

[2] xml.com, 'Introducing WSGI: Python's Secret Web Weapon, Part Two,
James Gardner'
<http://www.xml.com/lpt/a/1675>
[Accessed Monday, 9 October 2006]

Oct 9 '06 #7

P: n/a
Gregory Piñero wrote:
So I keep hearing more and more about this WSGI stuff, and honestly I
still don't understand what it is exactly
A protocol for web servers/python programs interaction. Just like CGI is
a protocol for web servers/whatever-language programs interactions.

Gregory, you'll find answers to most (if not all) of your questions in
the availables articles/tutorials on WSGI. You should really read them
first. FWIW, going from "what's this stuff" to "run my first WSGI app"
took me a couple hours. And porting your CGI apps to WSGI should be a
no-brainer.

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Oct 9 '06 #8

P: n/a
Sybren Stuvel wrote:
Gregory Piñero enlightened us with:
>So I keep hearing more and more about this WSGI stuff, and honestly I
still don't understand what it is exactly

AFAIK it's a standard for web frameworks.
It's not. It's a protocol for HTTP servers <-Python web applications
interaction, and barely higher-level than CGI itself.
In such a framework, you
receive a 'request' object, and return a 'response' object. If I'm
correct, the WSGI describes things like the method and property names
on those objects etc.
It's much more simple. The "request" is a CGI-environ like dict, the
"response" is made of a callable(http_code, *http_headers) plus an
iterable for the response's body. Here's the standard wsgi hello_world:

def hello_app(environ, start_response):
start_response('200 OK', [('Content-type', 'text/plain')])
return ['Hello WSGI World']
The WSGI spec is really dead-simple. It shouldn't take much more than 10
to 15 minutes to read and understand for anyone having some basic
knowledge about HTTP and web programming.

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Oct 9 '06 #9

P: n/a
Gregory Piñero wrote:
What I'm most confused about is how it affects me. I've been writing
small CGI programs in Python for a while now whenever I have a need
for a web program. Is CGI now considered "Bad"? I've just always
found it easier to write something quickly with the CGI library than
to learn a framework and fool with installing it and making sure my
web host supports it.
There's two aspects to CGI. As a method of deploying a web
application, it is fine (though slow). You can still deploy your
applications as CGI if you write them with WSGI. (This is covered some
in PEP 333)

There are some bad parts of CGI too, which won't work with WSGI. An
example is using "print" for output. WSGI is neutral about how your
application will run -- maybe it'll be a CGI script, maybe it'll be a
threaded server with long-running processes, maybe a forking server.
Also, you can't have statements at the module level, like you would
with a CGI script. All your code needs to be in functions. I think
these are all good ideas anyway.

One advantage of WSGI is that in addition to CGI you can easily set up
an HTTP server (there's one in wsgiref, for example). Then you can
develop and test your application locally.

Ian

Oct 9 '06 #10

P: n/a
Thanks for all the answers everyone. It's finally starting to come
together for me. Bruno, I tried reading some tutorials but perhaps I
made the content out to be more complicated than it really was and got
confused.

So my final question is if WSGI will work on any web hosting company
that supports Python. Mine currently is Nearly Free Speech and will
probably be running Python 2.5 soon (if that matters) I'd like to try
out web.py at some point on there. It looks like a nice framework.
Eventually maybe I'll try all of them.

(Sorry for not quoting here, but I'm kind of replying to everyone and
bottom posting would be really confusing I thinks? Mailing list
poetic license perhaps ;-)

-Greg
Oct 9 '06 #11

P: n/a
goon wrote:
Trying to research this on the web now

Lots of articles now appearing summarising WSGI ...

For definitive reference:

<http://www.python.org/dev/peps/pep-0333/[0]

Overview:

<http://www.xml.com/lpt/a/1674 [1] and
<http://www.xml.com/lpt/a/1675 [2]
And also the following article, by me, focusing on middleware:

http://www.ibm.com/developerworks/library/wa-wsgi/
(cover Weblog entry: http://copia.ogbuji.net/blog/2006-08-23/_Mix_and_m
)

--
Uche Ogbuji Fourthought, Inc.
http://uche.ogbuji.net http://fourthought.com
http://copia.ogbuji.net http://4Suite.org
Articles: http://uche.ogbuji.net/tech/publications/

Oct 10 '06 #12

This discussion thread is closed

Replies have been disabled for this discussion.