Skip to main content

Simple pipeline support for python

Project description

pipeline

This package is inspired by Elixirs pipelines. You can define an interable of callables and define them as pieline. The second element then gets the result of the first element and so on.

Example

Say you have some callables (see test/test_pipeline.py):

def add_age(item):
    item.age = 22
    return item

def add_name(name):
    def fun(item):
        item.name = name
        return item
    return fun

class AddHeight:

    def __init__(self, height):
        self.height = height

    def __call__(self, item):
        item.height = 192
        return item

Then you can compose them to a pipeline:

def some_name(arg):
    return pipeline(
        arg,
        add_age,
        inspect,
        add_name('Tom'),
        inspect(print),
        AddHeight(192),
    )

And use it as one:

class Plain:
    pass

plain_obj = Plain()
res = some_name(plain_obj)

assert res.age == 22
assert res.name == 'Tom'
assert res.height == 192

Inspect

For debugging, it is quite useful to inspect the intermediate result between two steps in the pipeline. This is easy with inspect:

def some_name(arg):
    return pipeline(
        arg,
        add_age,
        inspect,
        add_name('Tom'),
        inspect(print),
        AddHeight(192),
    )

Note that you can just use inspect, which usese pprint as default printer or pass a custom method in to print.

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

easy-pipeline-0.0.1.tar.gz (6.3 kB view hashes)

Uploaded Source

Built Distribution

easy_pipeline-0.0.1-py3-none-any.whl (6.5 kB view hashes)

Uploaded Python 3

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