Skip to main content

Framework for linking generators/iterators to processing chains, trees and graphs

Project description

The chainlet library offers a lightweight model to create processing pipelines from generators, coroutines, functions and custom objects. Instead of requiring you to nest code or insert hooks, chainlet offers a concise, intuitive binding syntax:

# regular nested generators
csv_writer(flatten(xml_reader(path='data.xml'), join='.'.join), path='data.csv')
# chainlet pipeline
xml_reader(path='data.xml') >> flatten(join='.'.join) >> csv_writer(path='data.csv')

Processing pipelines created with chainlet are an extension of generators and functions: they can be iterated to pull results, called to push input or even used to get/fetch a stream of data. The bindings of chainlet allow to compose complex processing chains from simple building blocks.

Creating new chainlets is simple, requiring you only to define the processing of data. It is usually sufficient to use regular functions, generators or coroutines, and let chainlet handle the rest:

@chainlet.genlet
def moving_average(window_size=8):
    buffer = collections.deque([(yield)], maxlen=window_size)
    while True:
        new_value = yield(sum(buffer)/len(buffer))
        buffer.append(new_value)

Features

We have designed chainlet to be a simple, intuitive library:

  • Modularize your code with small, independent processing blocks.

  • Intuitively compose processing chains from individual elements.

  • Automatically integrate functions, generators and coroutines in your chains.

  • Extend your processing capabilities with complex chains that fork and join as needed.

Under the hood, chainlet merges iterator and functional paradigms in a minimal fashion to stay lightweight.

  • Fully compliant with the Generator interface to integrate with existing code.

  • Implicit tail recursion elimination for linear pipelines, and premature end of chain traversal.

  • Push and pull chains iteratively, continuously, or even asynchronously.

  • Simple interface to extend or supersede pipeline traversal and processing.

At its heart chainlet strives to be as Pythonic as possible: You write python, and you get python. No trampolines, callbacks, stacks, handlers, …

We take care of the ugly bits so you do not have to.

Looking to get started? Check out our docs: Documentation Status

Found an issue or have suggestions? Head straight to our issue tracker: Open Issues

Status

We use the chainlet library in a production environment. It serves to configure and drive stream based data extraction and translation for monitoring. Both the grammar and general interfaces for processing chains, trees and graphs are stable.

Ongoing work is mainly focused on the iteration interface. We plan to add automatic concurrency, asynchronicity and parallelism. Our target is an opt-in approach to features from functional programming and static optimisations.

Recent Changes

v1.2.0

Synchronous concurrent traversal, chain slicing and merging, fully featured function and generator wrappers

v1.1.0

Added chainlet versions of builtins and protocol interfaces

v1.0.0

Initial release

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

chainlet-1.2.0.tar.gz (5.0 MB view hashes)

Uploaded Source

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