[PEAK] Interfacing Peak with Twisted
Phillip J. Eby
pje at telecommunity.com
Sat Mar 5 20:25:50 EST 2005
At 04:51 PM 3/4/05 -0100, Tiago Cogumbreiro wrote:
>On Fri, 04 Mar 2005 08:41:46 -0500, Phillip J. Eby
><pje at telecommunity.com> wrote:
> > You might have a look at:
> > http://peakplace.tigris.org/source/browse/peakplace/src/junction/
> > which was a work-in-progress by John Landahl that's basically a
> > Twisted/PEAK messaging server. It's not nearly as simple as an example, of
> > course.
>What does it exactly do?
I think it's some sort of messaging bridge between Twisted and something
else. :) Obviously, I don't know very much about it.
> > If your goal is an XML-RPC and/or web
> > front-end, may I suggest you first try peak.web?
>My goal is to designed an application with a big enfasis in storing
>information. However it must have a web based interface and provide
>webservices for a desktop client.
>Peak seems to be the most advanced framework in academic terms, it has
>a very interesting concept behind it and a very clean implementation.
>Yet it provides a number of technologies that I've never used before:
>ini files for configuration of your components, the way of starting
>your server (something about AbstractCommand).
Have you looked at the IntroToPeak tutorial on the Wiki? It teaches you
everything you should need to know to e.g. run the bulletins example or
create command-line applications.
> I've already understood
>(in theory) the concept behind adpative programming and component
>based programming but making the transition from that to an actual
>example is a really big step because of the lack of documentation.
>Where can I learn about these details?
That depends a lot on what specifically you want to learn. Most people
using PEAK right now are folks who've invested some time in reading the
source and experimenting, and then in some cases volunteered to write
documentation. IntroToPeak and the peak.web sample on the Wiki are both
instances of such contributions.
>However twisted already provides a vast array of types of servers and
>a simple framework to do it. So this is why I've chosen to use twisted
>in the connectivity part and peak in the logic part.
Sure. PEAK doesn't attempt to duplicate Twisted, only to integrate with
it. Essentially, if you use a component in a PEAK application that relies
on running.ITwistedReactor, it will end up referring to Twisted's reactor
instead of PEAK's relatively simple one. You can then use peak.events to
run pseudothreads against Twisted "deferreds", etc.
However, for a simple web application (even with XML-RPC), it's unlikely
you'll need this level of integration, and the WSGI interface is probably
quite sufficient, or even superior to using Twisted, as it can allow you to
take advantage of a multiprocessor system for scaling.
> > peak.web is runnable with
> > WSGI, which means it's runnable within Twisted, albeit only in a
> > single-threaded manner at the moment.
>What is WSGI?
WSGI is the Python Web Server Gateway Interface, an API for connecting web
applications written in Python to web servers. It is defined by PEP 333.
There are WSGI gateways for mod_python, Twisted, and CGI out there, and
PEAK has FastCGI and local HTTP WSGI gateways available as well. An
application written to the WSGI spec, or written to a framework (like
peak.web or Zope 3) that supports WSGI, can potentially be run in any
WSGI-supporting web server.
This is useful because for example the "peak launch" command will launch an
arbitrary WSGI-based application in a private web server and start your
browser pointing to it. This is often a nice way to develop, test, and
debug an application that you're working on. Once the application works as
you want it to, you can always deploy it in another WSGI-supporting web
server (such as Twisted).
>Is PyProtocol used in Peak too? I've already installed Peak, I don't
>need to install PyProtocols too, right?
No; PEAK always includes the latest PyProtocols. By the way, make sure
you're using the CVS version of PEAK; there hasn't been a source or binary
snapshot release in some time. (I should probably create an automated
More information about the PEAK