[Zope3-dev] PyProtocols 0.9

Phillip J. Eby pje@telecommunity.com
Sat, 07 Jun 2003 18:11:13 -0400


Do you hate having to write lots of if-then logic to test what type 
something is?  Wouldn't it be nice if you could just declare "I want this 
object to have this behavior" and magically convert whatever value you 
have, to the type you need?  PyProtocols lets you do just that, cleanly, 
quickly, and robustly -- even with built-in types or other people's classes.

PyProtocols extends the PEP 246 adapt() function with a new "declaration 
API" that lets you easily define your own interfaces and adapters, and 
declare what adapters should be used to adapt what types, objects, or 
interfaces.  In addition to its own Interface type, PyProtocols can also 
use Twisted and Zope X3's Interface types.  (Of course, since Twisted and 
Zope interfaces aren't as flexible, only a subset of the PyProtocols API 
works with them.  Specific limitations are listed in the documentation.)

If you're familiar with Interface objects in Zope, Twisted, or PEAK, the 
Interface objects in PyProtocols are very similar.  But, they can also do 
many things that no other Python interface types can do.  For example, 
PyProtocols supports "subsetting" of interfaces, where you can declare that 
one interface is a subset of another existing interface.  This is like 
declaring that somebody else's existing interface is actually a subclass of 
the new interface.  Twisted and Zope don't allow this, which makes them 
very hard to use if you're trying to define interfaces like "Read-only 
Mapping" as a subset of "Mapping Object".

Unlike Zope and Twisted, PyProtocols also doesn't force you to use a 
particular interface coding style or even a specific interface type.  You 
can use its built-in interface types, or define your own.  If there's 
another Python package out there with interface types that you'd like to 
use (CORBA? COM?), you can even create your own adapters to make them work 
with the PyProtocols API.

PyProtocols is also the only interface package that supports automatic 
"transitive adaptation".  That is, if you define an adapter from interface 
A to interface B, and another from B to C, PyProtocols automatically 
creates and registers a new adapter from A to C for you.  If you later 
declare an explicit adapter from A to C, it silently replaces the 
automatically created one.

PyProtocols may be used, modified, and distributed under the same terms
and conditions as Python or Zope.


PyProtocols resources include:

* Release notes, installation instructions, and browsable API docs:
   http://peak.telecommunity.com/protocol_api/

* Source and Binary Releases:
   http://peak.telecommunity.com/dist/

* Reference Manual (HTML):
   http://peak.telecommunity.com/protocol_ref/module-protocols.html

* Reference Manual (PDF):
   http://peak.telecommunity.com/protocol_ref.pdf

* Browsable CVS Repository:
   http://cvs.eby-sarna.com/PyProtocols/


Version 0.9 of PyProtocols is a complete, working release, so you can 
download it now and try it out.  But, the exact spellings of the API and 
other interfaces may be subject to change in the future.  We would like 
feedback from the community on the current API, as some API names may not 
be clear or obvious yet.  Please contact the author with your input.