Introducing the wftk Workflow Toolkit

The wftk is an open-source workflow toolkit written by Michael Roberts of, who has lavished much effort on it since its inception in 2000. It is written in ANSI C and has a well-tested interface into Python, so it's a strong choice for writing enterprise-oriented code in Python.

The one thing you have to keep in mind when writing to the wftk, however, is that you're not just sitting down to write code. As explained at the outset of this chapter, enterprise programming is all about modeling business processes, and the wftk reflects that basic approach. Before doing anything else, you have to describe the context of the actions and objects with which you'll be working. After a while, this gets to be second nature, but until it does, it may feel unnatural.

It makes sense to talk about a repository first when starting to build a system using the wftk. The repository defines the context for everything else in a wftk system. The key part of the repository definition is the lists it defines. A list is simply a data source—in terms of relational databases, a list can be seen as a table, because it contains entries that have corresponding records. However, there are some differences:

□ An entry always has a unique key that can be used to reference it.

□ An entry need not consist of a fixed number or assortment of fields (data values).

□ An entry can also contain arbitrary XML.

□ An entry can include any number of named attachments, each of which can have a version list.

It's important to realize that these are simply the capabilities of a general list; real lists stored in real actual places may only offer a portion of these capabilities based on your decisions.

The other salient feature of the repository and the repository manager is that everything is managed by adapters. An adapter is a fairly compact set of code that defines an external interface. For instance, there are adapters to store list entries in a local directory as XML files, or in a relational database table (MySQL, Oracle, or a generic ODBC database) as lines in a text file, and so on. In addition, it's simple to write new adapters to treat other resources as suitable locations for the storage of repository lists.

In other words, when the task is to write some simple code to do something in the context of an already existing set of information resources, the first task is to describe those resources as lists so that the repository manager knows what's where. The bigger examples will step through a couple of systems in detail, but initially you can look at a few much simpler examples so you can see how it's done. All of these examples assume that you have already installed the wftk and it is running in your Python installation (see Appendix B for the wftk home page, and this book's web site at for more thorough instructions on installing the wftk on your computer).

For your first foray into the wftk, set up an extremely simple repository and write a few scripts to save and retrieve objects. Generally, a wftk repository is a local directory in which the repository definition is saved as an XML file named system.defn. Subdirectories can then be used as default list storage (with each entry in an XML file of its own), and a convenient event log will be written to repository.log in the repository directory. If you haven't read Chapter 15 on XML and Python yet, you can look there if you are confused. In addition, remember that all of this text will be on the book's web site.

Try It Out Very Simple Record Retrieval

1. Create a directory anywhere you want; this directory will be your repository (all the following examples will reside in this directory). Using the text editor of your choice, open the file system.defn in that directory, and define the repository's structure like this:

<repository loglevel="6">

<list id="simple">

<field id="field1" special="key"/>


2. Save the file and then create a subdirectory named simple. Just to make things easy, use your text editor to add a file in the new subdirectory named first and add the following contents to it:











3. Save the record and then return to the main directory and add a new Python script named This script is going to retrieve lists of keys and then the object you just created. Again using your text editor, enter the following code:

import wftk repos = wftk.repository('site.opm')

print l

e = repos.get('simple',


print e

print e.string()


print e['field1']

4. Now run the simple retrieval script:


<rec key="first" list="simple"> field id="field1">value1</field> field id="field2">value2</field> </rec>

<rec key="first" list="simple"> field id="field1">value1</field> <field id="field2">value2</field> </rec>


Was this article helpful?

0 0