Kamaelia docs : Kamaelia.Util.Filter

Simple framework for filtering data

A framework for filtering a stream of data. Write an object providing a filter(...) method and plug it into a Filter component.

Example Usage

Filters any non-strings from a stream of data:

class StringFilter(object):
    def filter(self, input):
        if type(input) == type(""):
            return input
            return None            # indicates nothing to be output

myfilter = Filter(filter = StringFilter).activate()

How does it work?

Initialize a Filter component, providing an object with a filter(...) method.

The method should take a single argument - the data to be filtered. It should return the result of the filtering/processing. If that result is None then the component outputs nothing, otherwise it outputs whatever the value is that was returned.

Data received on the component's "inbox" inbox is passed to the filter(...) method of the object you provided. The result is output on the "outbox" outbox.

If a producerFinished message is received on the "control" inbox then it is sent on out of the "signal" outbox. The component will then terminate.

However, before terminating it will repeatedly call your object's filter(...) method, passing it an empty string ("") until the result returned is None. If not None, then whatever value the filter(...) method returned is output. This is to give your object a chance to flush any data it may have been buffering.

Irrespective of whether your filtering object buffers any data from one call to the next, you must ensure that (eventually) calling it with an empty string ("") will result in None being returned.


class Filter(Axon.Component.component)

Filter([filter]) -> new Filter component.

Component that can modify and filter data passing through it. Plug your own 'filter' into it.

Keyword arguments:

  • filter -- an object implementing a filter(data) method (default=NullFilter instance)


  • control : Shutdown signalling
  • inbox : Data to be filtered


  • outbox : Filtered data
  • signal : Shutdown signalling

Methods defined here


You should be using the inbox/outbox interface, not these methods (except construction). This documentation is designed as a roadmap as to their functionalilty for maintainers and new component developers.

__init__(self[, filter])

x.__init__(...) initializes x; see x.__class__.__doc__ for signature


Flush any data remaining in the filter before shutting down.


Main loop body.


Got a problem with the documentation? Something unclear that could be clearer? Want to help improve it? Constructive criticism is very welcome - especially if you can suggest a better rewording!

Please leave you feedback here in reply to the documentation thread in the Kamaelia blog.

-- Automatic documentation generator, 05 Jun 2009 at 03:01:38 UTC/GMT

Kamaelia is an open source project originated from and guided by BBC Research. For more information browse the site or get in contact.

This is an ongoing community based development site. As a result the contents of this page is the opinions of the contributors of the pages involved not the organisations involved. Specificially, this page may contain personal views which are not the views of the BBC. (the site is powered by a wiki engine)

(C) Copyright 2008 Kamaelia Contributors, including the British Broadcasting Corporation, All Rights Reserved.

This web site is powered by the same code created for the bicker manor project. For more details, contact Michael Sparks at BBC Research directly (cf contact)