|Version 2 (modified by glyph, 11 years ago) (diff)|
Web Development with Twisted
Twisted has a long and checkered past in web development. This page is a roadmap to the wilderness that the landscape of web development with Twisted has become.
What's Going On Around Here
There are a number of packages in and around Twisted that do things with the web:
- Twisted Web provides a simple, stable resource publishing API, on top of an HTTP/1.0 server implementation with some HTTP/1.1 features. Twisted Web is widely regarded as clunky and old, but extremely stable.
- Several deprecated templating toolkits included with twisted.web, such as "woven" and "twisted web widgets". Don't use these! They're only there for compatibility.
- Twisted Web 2? is a complete re-write of Twisted Web, with a new HTTP/1.1 implementation and a new, more powerful and efficient resource publishing model. Unfortunately, it is currently still a work in progress. Some aspects of its design are not finalized, but it is ready for interested early-adopting developers. If you are going to use Web 2, you really need to stay current with recent developments in Twisted; subscribe to RSS feeds of changes to trunk, etc.
- Divmod Nevow is a templating toolkit that provides its own resource model and simple application server API. It requires Twisted, is fully integrated with the Twisted reactor, provides mechanisms for asynchronous page rendering, and an event-driven COMET/AJAX implementation called Nevow Athena. Currently Nevow uses Twisted Web but it will be ported to Twisted Web 2 once that stabilizes.
- Divmod Mantissa is a full-featured multi-protocol application server, with a built-in object database, authentication model based on Twisted Cred, a capability-based security model, and many more features. It integrates Nevow, twisted.web, and a number of other Twisted-related technologies to provide a full-featured system.
So You Want To Be A Web Developer
Having reviewed this list, the obvious question is, which of these tools should I use for my application??? The short answer is: "It depends."
Here are some different things you might be trying to do with Twisted.
I want a web UI for my existing Twisted networking application
Assuming that your networking application has its own data persistence, or does not require persistence, and needs a web-based control panel or monitoring UI, you probably want to use Nevow. While not completely stable, Nevow provides some degree of backwards compatibility between releases, and will insulate you from the upcoming Twisted Web -> Twisted Web 2 transition. It will also make designing user interfaces that integrate with the event loop much easier than coding directly to either the Web or Web 2 APIs.
If you want a spiffier interface and you are willing to invest a bit more work, most of these comments about relative API stability also apply to Nevow Athena, and Athena lets you take advantage of the event loop on multiple levels; you can push events from network triggers straight out to a web page.
Unfortunately neither Nevow nor Athena is completely stable; there has not yet been a 1.0 release. But neither are they churning rapidly and requiring up-to-the-minute monitoring of development. They also have an active community that understands Twisted integration issues well.
I want a container for my WSGI application
In this case it's suggested that you use Twisted Web 2. In this case the instability of the API shouldn't concern you much, since your application should already be written to the stable (standardized, even) WSGI API. In this sense you are really just using the webserver as a tool rather than an API, and Twisted Web 2 is ready for that kind of use. Zope 3 has been using it in this capacity and (so far) it seems to be working fine.