473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

WSGI - How Does It Affect Me?

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
11 1809
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
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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Thomas W | last post by:
Will there be a WSGI-server like BaseHTTPServer etc in the standard distro? I think that would increase the adoptation of the WSGI-standard. A new web-framework for python pops up every other week...
2
by: Ben Finney | last post by:
Howdy all, I'm trying to implement some new functionality for an existing PHP web application. Rather than writing a whole lot of stuff in PHP, and looking toward a future when more of the...
1
by: seberino | last post by:
I love idea of WSGI and hope it succeeds. It seems to be helpful for person tempted to write his own framework.....they can now just mix and match existing components with WSGI //instead//. I...
7
by: Ben Finney | last post by:
Howdy all, I'm working on a web application that is starting to gain a lot of back-end code written in Python. However, all the current interface code is written in legacy PHP. I'd like to...
2
by: Adam Atlas | last post by:
I'm trying to figure out if there's any defined behaviour in PEP 333 for instances where an application returns an iterable as usual without error, but that iterable's next() method eventually...
8
by: Ron Garret | last post by:
The wsgiref module in Python 2.5 seems to be empty: $ python Python 2.5 (r25:51908, Mar 1 2007, 10:09:05) on darwin Type "help", "copyright", "credits" or "license" for more information. ...
37
by: Michele Simionato | last post by:
At work we are shopping for a Web framework, so I have been looking at the available options on the current market. In particular I have looked at Paste and Pylons and I have written my...
9
by: Tool69 | last post by:
Hi, Until now, I was running my own static site with Python, but I'm in need of dynamism. After reading some cgi tutorials, I saw Joe Gregorio's old article "Why so many Python web...
4
by: inhahe | last post by:
I'm sorry if this is off-topic, i couldn't find a mailing list OR forum for WSGI (and #wsgi wasn't very helpful). i played around with StringIO, and apparently if you write to a stringio the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.