Skip to main content

Kamaelia - Multimedia & Server Development Kit

Project description

Kamaelia, A fast overview

Kamaelia is a Python library by BBC Research for concurrent programming using a simple pattern of components that send and receive data from each other.

Note: this is the first alpha release of the Kamaelia ‘refresh’ project to bring Kamaelia up to date with the modern python ecosystem.

A quick overview

The following is an example of a system made by piping the output of one component into another:
from Kamaelia.Chassis.Pipeline import Pipeline
from Kamaelia.Util.Console import ConsoleReader, ConsoleEchoer

Pipeline(
         ConsoleReader(),
         ConsoleEchoer(),
).run()

Or maybe you want to build a presentation tool? (imports & setup excluded here)

Graphline(
     CHOOSER = Chooser(items = files),
     IMAGE = Image(size=(800,600), position=(8,48)),
     NEXT = Button(caption="Next", msg="NEXT", position=(72,8)),
     PREVIOUS = Button(caption="Previous", msg="PREV",position=(8,8)),
     FIRST = Button(caption="First", msg="FIRST",position=(256,8)),
     LAST = Button(caption="Last", msg="LAST",position=(320,8)),
     linkages = {
        ("NEXT","outbox") : ("CHOOSER","inbox"),
        ("PREVIOUS","outbox") : ("CHOOSER","inbox"),
        ("FIRST","outbox") : ("CHOOSER","inbox"),
        ("LAST","outbox") : ("CHOOSER","inbox"),
        ("CHOOSER","outbox") : ("IMAGE","inbox"),
     }
).run()
That’s all well and good, but how is a component written? What’s inside it?
from Axon.Component import component
from Axon.Ipc import shutdownMicroprocess, producerFinished

class MyComponent(component):
    Inboxes = {"inbox"        : "some data in",
               "control"      : "stops the component"}
    Outboxes = {"outbox"      : "some data out",
                "signal"      : "Shutdown signal"}

    def __init__(self, **argd):
        super(MyComponent, self).__init__(**argd)

    def main(self):
        while not self.doShutdown():
            if self.dataReady("inbox"):
                data = self.recv("inbox")
                # let's echo what we received...
                self.send(data, 'outbox')

            if not self.anyReady():
                self.pause()

            yield 1

    def doShutdown(self):
        if self.dataReady("control"):
            mes = self.recv("control")
            if isinstance(mes, shutdownMicroprocess) or isinstance(mes, producerFinished):
                self.send(producerFinished(), "signal")
                return True
        return False

This is the simplest form a component can take. A component:

  • is a class that inherits from Axon.Component.component

  • has inboxes and outboxes

By inheriting from Axon.Component.component you make your class usable by the Axon library which is at the core of the Kamaelia library. It allows for your class to be used with other components.

Inboxes and outboxes allow your component to be linked to and from by other components.

Then your class defines a main method that simple loop until a specific kind of message is put into the “control” inbox of the component. During the looping it checks for any inboxes and process data read from them. Eventually it yields to the Axon scheduler that goes to the next available component. By using a generator we allow the shceduler to come back to the component’s loop eventually.

Note that inboxes and outboxes are pure Python dictionary hence they allow for any Python objects and are not limited to strings. The component described above is simple, complex components have many inboxes and outboxes to link to and from.

Kamaelia

Kamaelia is a library of components for all kind of tasks and topics:

For example taking the previous example we could write:

from Kamaelia.Chassis.Pipeline import Pipeline
from Kamaelia.Util.Console import ConsoleReader, ConsoleEchoer

Pipeline(
         ConsoleReader(),
         MyComponent(),
         ConsoleEchoer(),
).run()

Pipeline is component that automatically links outboxes to inboxes of each provided component. The console components allow for reading and writing data from and to the command line. Because Pipeline is also a component itself it could in turns be used in another component.

Note that calling the run() method on a component blocks the process until it is killed. You can also simply activate a component which will then be in an active state but will run only when eventually run is called on another component.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kamaelia-1.14.32.tar.gz (4.6 MB view details)

Uploaded Source

File details

Details for the file kamaelia-1.14.32.tar.gz.

File metadata

  • Download URL: kamaelia-1.14.32.tar.gz
  • Upload date:
  • Size: 4.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for kamaelia-1.14.32.tar.gz
Algorithm Hash digest
SHA256 aa1bf32c7b404f5aeefc2191b9710a67e783c4634be6cb9a88ee20f5e6117dfd
MD5 c879543304e2728ee05ac670073b1b85
BLAKE2b-256 a32fef98a48c9c83fedb82c1d6a9498d097de0980b9d72bc08e4281017d60d53

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page