Armin Ronacher: the future of WSGI and Python 3

Tags: django, djangocon

Armin is a true WSGI believer. And he’s part of the Pocoo team: jinja, werkzeug, sphinx and so on.

He asked for a show of hands: how many people are already using python 3 in some way? Perhaps 5% of the hands went up…

WSGI (pronounced “wiskey”) is pep 333. Almost every web framework is using it now. WSGI is a gateway interface, we’re currently expecting too much out of it if you look at how it is used. Middleware (plug-ins) is often abused.

There are some, partially theoretical, WSGI issues like input stream is not delimited, some read()/readline() issue, path info is not URL encoded. And a small, mostly unused, part of the http protocol isn’t implemented. In the real (Django) world, most of the issues aren’t a problem.

The biggest difference in Python 3 is the string handling. You now either have a bytestring or unicode. Every string is now unicode: everything not-unicode is explicitly an encoded bytestring. Explicit is better than implicit. A problem is that stdin is now a string (so: unicode) input. And stdin is used for cgi: so you cannot receive binary data anymore, sigh. And URIs also aren’t unicode based. Summary:

  • urllib is unicode.

  • sys.stdin is unicode.

  • os.environ is unicode (only new windows versions are unicode OSs).

  • http and wsgi are not unicode.

The result is that the reference wsgi server in standard python 3 is now, well, broken. In the end, python 3 was supposed to make unicode easier but in the wsgi case, it is causing a lot more problems than unicode environments on python 2. WSGI on python 3 is not possible at the moment.

Armin showed some changes that have to be made to get it working. Mostly you have to do a lot more encode/decode combinations to please the standard library. And partially you have to implement your own originally-stdlib functionality.

What Armin thinks will happen:

  • stdlib won’t be used that much in WSGI apps.

  • Writing middleware becomes a whole lot harder if not impossible.

  • Frameworks will probably reimplement urllib and cgi stlib modules.

  • Probably WebOb will be used by frameworks to get a standard way to work around the problem

Armin’s pony request: get involved in wsgi and play with the specification. Subscribe to web-sig.

Armin himself is probably not going to use python 3 himself anytime soon. But he dislikes it when python fractures in a python 3 community for desktop applications and python 2 for web applications. The python 3 stdlib is currently incredibly broken but because there are so few users, these bugs stay under the radar. Also read up on Graham’s posts about this topic.

Update: on twitter, jjrz pointed at a great t-shirt that’s perfect for this topic :-)

 
vanrees.org logo

Reinout van Rees

My name is Reinout van Rees and I program in Python, I live in the Netherlands, I cycle recumbent bikes and I have a model railway.

Weblog feeds

Most of my website content is in my weblog. You can keep up to date by subscribing to the automatic feeds (for instance with Google reader):