The PEAK Developers' Center   IntroToPeak UserPreferences
HelpContents Search Diffs Info Edit Subscribe XML Print View
The following 421 words could not be found in the dictionary of 50 words (including 50 LocalSpellingWords) and are highlighted below:
Also   An   And   As   Attribute   Bash   Batch   Build   By   Changes   Class   Commands   Component   Configuration   Cygwin   Data   David   Do   Domain   Don   Eby   Exploring   Extended   Files   Five   For   Four   Generally   Hello   Help   How   If   In   Introduction   It   Key   Lesson   Lessons   Logs   Models   Murray   N2   Name   Need   Non   None   Not   Note   Obtain   On   One   Options   Other   Phillip   Prerequisites   Property   Python   Python22   Retrieval   Root   Scripts   So   Storing   Subcommands   Substituting   The   There   Thing   Three   To   Two   Unfortunately   Unix   Unixes   Unixish   Usage   Using   We   Why   Windows   World   You   able   about   above   access   according   adaptable   advertised   against   all   alluded   alpha   also   although   among   an   and   another   application   applications   are   areas   argument   arguments   around   as   assistance   at   attached   attributes   bar   basic   be   become   been   begin   below   between   bin   binding   bit   bitdance   build   but   by   caches   calling   can   case   change   changes   check   child   class   code   com   command   complete   component   components   concept   config   configurable   configuration   constructor   contained   container   containers   conveniences   correct   could   course   cover   covered   create   current   database   deep   default   demonstrate   develop   doc   documentation   does   driven   earlier   easy   either   env   environment   errors   essentials   etc   example   examples   exe   expect   explore   export   extremely   feature   features   file   find   finds   first   flavor   for   found   framework   frameworks   from   fun   future   get   giving   going   have   haven   having   help   here   hierarchy   how   however   hump   if   important   in   included   indicate   initial   install   instances   instead   instructions   intended   invoke   is   issues   it   its   journey   just   key   keyword   kind   kinds   know   knowledge   latest   left   lengths   lesson   lessons   let   like   limited   line   lines   list   little   ll   local   logging   long   look   lookup   made   mailing   major   make   many   me   meantime   mechanisms   module   more   must   my   naming   navigate   need   needed   needs   not   note   nothing   notification   objects   obtain   occasion   of   offer   on   once   one   open   operating   options   or   order   other   our   out   over   package   parent   path   paths   peak   percent   pje   please   possible   probably   process   program   programmers   programming   programs   prompt   prop   provide   provided   provides   purpose   question   quick   rdmurray   re   read   receive   record   refer   reference   repeatedly   rest   revolve   rewrite   root   run   running   same   script   see   self   separated   series   service   services   set   setting   shell   should   sign   simple   so   some   something   sophisticated   space   speaking   specific   specified   standard   start   started   still   stripped   such   supplied   support   synchronization   system   systems   talking   teaching   telecommunity   test   tested   that   the   their   them   then   there   these   they   thing   things   this   thoughts   through   to   top   topic   topics   tradition   transactions   treat   trouble   try   tutorial   under   understanding   unixes   up   updated   use   used   users   using   usr   value   variables   various   ve   version   versions   via   want   way   we   web   whatever   when   which   while   will   wish   with   within   without   work   working   write   written   you   your  

Clear message

An Extended Introduction to PEAK

By R. David Murray (rdmurray at, with assistance from Phillip J. Eby (pje at

There's a long tradition of teaching programmers how to use programming systems via "Hello, World!" examples. Why should PEAK be left out? I'm going to try to develop a series of stripped-to-the-essentials examples here that provide complete working PEAK programs that demonstrate some of the basic services provided by PEAK. Don't expect to find deep knowledge here; these lessons are intended to help you get over the first hump of using PEAK, while giving you a little bit of its "flavor".

The examples all revolve around a simple "Hello, World!" application concept. We'll start with a basic "Hello, World!" command-line application, then make it configurable, use various kinds of database access with transactions and logging, all the way up through a web UI and XML-RPC "web service", among other things. In the process, you'll be able to see how easy it is to create, re-use, and re-purpose component-driven applications with PEAK.

Lesson Prerequisites

The examples in the lessons below have been tested against the latest CVS version of PEAK 0.5 alpha 3. The examples will not work with earlier versions of PEAK. (There could also be synchronization errors between the examples and my test code, so if you find something that doesn't work as advertised when run against current CVS, please let me know.)

We'll be using a Unixish command shell for our examples. The percent sign (%) will be used to indicate a command prompt.

Windows users: if you're not using a Unix-like shell (e.g. Cygwin/Bash), you'll need to change the command lines used here. For example, peak foo bar will become something like c:\Python22\Python.exe c:\Python22\peak foo bar. None of the #! lines will work for you, either, and to set environment variables like PYTHONPATH, you'll need to use SET instead of export, and so on.

Note, however, that there's nothing Unix-specific about the framework or examples, and your applications will still run on Windows. It's just that the standard Windows shell doesn't offer as many conveniences in these areas. If you have trouble running the examples on Windows, write up your question on the PEAK mailing list, and we'll try to get the examples updated with more Windows-specific command lines.

Non-BSD Unix users: The #! lines in this tutorial are written for BSD-like Unixes that treat #! lines as having space-separated arguments. On other unixes, you will need to rewrite the #! lines to use the invoke program included with PEAK. Build and install the invoke program according to the instructions in PEAK's INSTALL.txt file, and make note of its path. You will need to change #! lines that look like:

#!/usr/bin/env peak runIni 
to read:
#!/usr/local/bin/invoke peak runIni 
instead. (Substituting the correct path to invoke, of course.)

invoke doesn't support setting the environment like env does, so you'll need to use something like:

`#!/usr/local/bin/invoke env WHATEVER=whatever peak whatever` 
if a #! line needs to set something in the environment.

Unfortunately, some operating systems have extremely limited lengths for #! lines, and you may have to create a shell script and invoke it via #!invoke in order to get all of the arguments you need. For more on this, see [WWW]PEAK's INSTALL.txt, under "Scripts, Batch Files, and #!".

The Lessons

Exploring the rest of PEAK

One important topic we haven't covered in the lessons above is the "component hierarchy", although we've alluded to it on occasion by talking about "parent" and "child" components. Generally speaking, a component contained within another component is a "child" component of the container, and PEAK provides mechanisms for components to access their containers to "obtain" configuration or other components. It's also possible to treat the component hierarchy like a kind of file system, using paths to navigate from one component to another.

As you begin to build more sophisticated applications, you'll probably want to have more understanding of how components are attached to their parent components, and how they can receive notification that they've been attached. And, if you want to create applications that run without using the peak script, you'll also want to know about "root components" and how to create them with config.makeRoot.

In the meantime, to get you started on your journey, you may wish to explore the [WWW]current API documentation. There, you'll find a list of some of the major features provided by other PEAK frameworks, and quick-reference documentation for them. Also, if you want to look up an API feature like PropertyName or binding.Obtain, you can use the peak help command, e.g.:

% peak help binding.Obtain 
Help on class Obtain in module peak.binding.components: 
class Obtain(peak.binding.once.Attribute) 
 | 'Obtain(componentKey,[default=value])' - finds/caches a needed component 
 | Usage examples:: 
 | class someClass(binding.Component): 
 | thingINeed = binding.Obtain("path/to/service") 
 | otherThing = binding.Obtain(IOtherThing) 
 | aProperty = binding.Obtain(PropertyName('some.prop'), default=42) 
 | 'someClass' instances can then refer to their attributes, such as 
 | 'self.thingINeed', instead of repeatedly calling 
 | 'self.lookupComponent(someKey)'. 
 | The initial argument to the 'Obtain' constructor must be adaptable to 
 | 'binding.IComponentKey'. If a 'default' keyword argument is supplied, 
 | it will be used as the default in case the specified component key is not 
 | found. 
 ... etc. 

(Also, this tutorial doesn't cover how to make your command objects support options like --help; for that, you can check out options.txt in the peak.running package, or have a look at the OptionsHowTo, which is the same thing but in HTML.)

So have fun with PEAK, and I'll see you at the top!

EditText of this page (last modified 2005-07-27 14:27:18)
FindPage by browsing, title search , text search or an index
Or try one of these actions: AttachFile, DeletePage, LikePages, LocalSiteMap, SpellCheck