Skip to main content

A utility for calling functions in pipelines.

Project description

Pipeline Functions

Last release Python version Test status Test coverage Last commit

Pipeline Functions is a simple utility for calling functions in "pipelines", i.e. where the output from one function is automatically the input for the next. Here's an example showing how this works:

>>> from pipeline_func import f
>>> def keep_odd(items):
...     return [x for x in items if x % 2 == 1]
>>> def keep_greater(items, threshold):
...     return [x for x in items if x > threshold]
>>> range(10) | f(keep_odd) | f(keep_greater, 4)
[5, 7, 9]

Contrast this to the harder-to-read style required to call these same functions without this library:

>>> numbers = range(10)
>>> numbers = keep_odd(numbers)
>>> keep_greater(numbers, 4)
[5, 7, 9]

The only API provided by this library is the f function. The first argument should be a callable object. The remaining arguments can be arbitrary positional or keyword arguments. Call the function by using the | operator as shown above. The output from the left-hand side of the operator will be the first argument to the function. Any extra arguments provided to f() will be added after.

This library only works if each pipeline function has exactly one input and one output. It also requires that the initial input object does not implement the left | operator for pipeline_func.PipelineFunc objects. This should be true for any well-behaved object, though.

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

pipeline_func-0.1.0.tar.gz (2.2 kB view hashes)

Uploaded Source

Built Distribution

pipeline_func-0.1.0-py3-none-any.whl (2.2 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