473,587 Members | 2,527 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1827
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*******@your thirdtower.com. imaginationwrot e:
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: "contractua l obligation"

-- Theerasak
Oct 8 '06 #3
Theerasak Photha enlightened us with:
3. Using IIS [...]

Why would you want to use that monstrosity?

Two words: "contractua l 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(envi ron, start_response) :
"""Simplest possible application object"""
status = '200 OK'
response_header s = [('Content-type','text/plain')]
start_response( status, response_header s)
return ['Hello world!\n']

To serve it as a CGI just:
from wsgiref.handler s import CGIHandler
CGIHandler().ru n(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(s imple_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_ser ver('',8080, app)
s.server_foreve r()

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.o rg

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_c ode, *http_headers) plus an
iterable for the response's body. Here's the standard wsgi hello_world:

def hello_app(envir on, 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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1270
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 and more and more support WSGI. Why not focus on getting an optimized, production-grade fully documented WSGI-server into the distro? Right now the...
2
1392
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 application can be rewritten more sanely, I'd like to write a Python program that generates the content and serves it up to the existing application via...
1
1229
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 not sure what WSGI offers the web beginner. Aren't they still better off learning an existing web framework first before attacking WSGI?
7
1816
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 slowly introduce new features as Python WSGI programs. Is it possible to write a Python WSGI program that talks to a PHP program as its "back end"?...
2
1182
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 raises an exception. Since any data theretofore returned by the iterable must be assumed to have already been written to the client, thus making it...
8
2304
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. So... is wsgi considered ready for production use, or is it still on the bleeding edge? And if the former, which implementation should one use?
37
2549
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 impressions here: http://www.phyast.pitt.edu/~micheles/python/yet-another-comparison-of-web-frameworks.html I do not speak too well of Pylons, so if you...
9
3234
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 frameworks?" about wsgi apps and have a question about it. The code he gave works like a charm (I had to make a little change because SQLAlchemy has changed...
4
2676
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 position gets set to the end of the write, so if you read from it again, without using seek, you won't read what comes next, you'll skip to the end of...
0
7920
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7849
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8347
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7973
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5718
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1189
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.