Armin Ronacher: Keynote: State of webdev in Python

published May 20, 2011

Summary of keynote at the PyGrunn conference.

Armin Ronacher gives the keynote "State of webdev in Python", at the PyGrunn conference in Groningen, The Netherlands. Organized by Paylogic and Goldmund Wyldebeast & Wunderliebe.

I am founding member of the Pocoo Team, doing Jinja2, Crossroads, Werkzeug, etc. Python 3 is kind of the elephant in the room that no one is talking about. So Python in 2011 has the big Python 2 versus 3 debate. 'Unladen Swallow' is resting, Python 3.2 was released, the packaging infrastructure is being worked on, including distutils2.

PyPy has become really fast. PyPy is Python written in Python. PyPy trunk is on average 3.7 times faster than the standard CPython, see http://speed.pypy.com. There is only experimental support for the Python C API. Different garbage collection behavior, no reference counting. So a few things will break, depending on what you are using it for. Django, ctypes, pyglet, twisted, all work.

All language development is now happening on Python 3. It adds unicode to the whole stack. The language is cleaned up. It does break backwards compatibility. Most code does not run on both 2 and 3, but a few packages do (lxml, at least at some point). It introduces unicode in exceptions and source compilation as well as identifiers (although I urge you not to try that). Greatly improved I/O API for unicode. Some new language constructs. Implementation was cleaned up a lot.

New constructs: extended iterable unpacking (a, *b = some_iterable), keyword-only arguments, nonlocal, function parameter and return value annotations (use them e.g. for documentation purposes).

print is now a function. Improved syntax for catching and raising exceptions. Ellipsis (...) syntax element.

Some different behaviours. More powerful metaclasses. List comprehensions are closer to generators now. Lesson: don't rely on undocumented 'features'.

Classic classes are gone. Imports are absolute by default.

Python 2.6 and 2.7 make it possible to write code that you can run through the 2to3 program to turn it into Python 3 code. You can use abstract base classes to check for certain implementations (not: is this a dict, but: is this dict-like).

Do you want beauty of code? Use Python 3. Do you want raw speed? Use PyPy.

Numeric libraries work great on Python 3 and benefit from improvements in the language.

Predictions:

  • Most people will write their code against 2.7 with the intention of supporting PyPy.
  • Libraries that require the C API will become less common.
  • We will see libraries that support targeting both Python 2.7 and 3.x.

Now the second part of this talk: Python and the Web.

WSGI has a new specification for Python 3. Some work is done to port implementations to Python 3. It just works; not really an issue anymore.

New developments: Improvements to PyPy support for database adapters. Improvements in template compilation in e.g. Django to take advantage of PyPy's behaviour. Some libraries are being ported over to Python 3.

Python 3 can work. You can start porting libraries over. Issues will only be resolved if you actually try to port. Higher level code is usually easier to port; low level libraries are trickier. Porting is easier if you drop support for 2.6. For porting, see http://bit.ly/python3-now.

WSGI works well in practice on Python 3. Pylons and BFG are now Pyramid, which is a nice introduction into the Zope world. There is less and less framework specific code out there; it is easier to share code.

At the low level, Werkzeug and WebOb may merge at some point; they are much alike.

Frameworks are good. In new frameworks we can explore new paradigms and concepts. It is surprisingly easy to switch frameworks or parts of them. Frameworks themselves are even merging.

I think PyPy will gain more traction in the python web world. It may eventually become more popular than CPython. Supporting Python 3 in PyPy should be easier than Python 2.

Things like 0MQ (Zero MQ) may help to have parts of your code in Python 2 and part in Python 3.