Skip to main content

A Python library for defining, managing, and executing function pipelines.

Project description

pipefunc: function composition magic for Python

Lightweight function pipeline creation: 📚 Less Bookkeeping, 🎯 More Doing

Python PyPi Code style: black pytest Conda Coverage Documentation Downloads GitHub

:books: Table of Contents

:thinking: What is this?

pipefunc is a Python library that simplifies the creation and management of complex function pipelines. It allows you to declare the dependencies between functions and automatically organizes the execution order to satisfy these dependencies.

pipefunc provides a range of features to streamline your workflow, including pipeline visualization, flexible function arguments, support for multiple outputs, pipeline simplification, resource usage profiling, parallel execution, caching, and parameter sweep utilities.

Whether you're working with data processing, scientific computations, machine learning (AI) workflows, or any other scenario involving interdependent functions, pipefunc helps you focus on the logic of your code while it handles the intricacies of function dependencies and execution order.

:rocket: Key Features

  1. 🚀 Function Composition and Pipelining: Create pipelines where the output of one function feeds into another, with pipefunc handling the execution order.
  2. 📊 Pipeline Visualization: Generate visual graphs of your pipelines to better understand the flow of data.
  3. 💡 Flexible Function Arguments: Call functions with different argument combinations, letting pipefunc determine which other functions to call based on the provided arguments.
  4. 👥 Multiple Outputs: Handle functions that return multiple results, allowing each result to be used as input to other functions.
  5. ➡️ Pipeline Simplification: Merge nodes in complex pipelines to improve computational efficiency, trading off visibility into intermediate steps.
  6. 🎛️ Resource Usage Profiling: Get reports on CPU usage, memory consumption, and execution time to identify bottlenecks and optimize your code.
  7. 🔄 Parallel Execution and Caching: Run functions in parallel and cache results to avoid redundant computations.
  8. 🔍 Parameter Sweep Utilities: Generate parameter combinations for parameter sweeps and optimize the sweeps with result caching.
  9. 🛠️ Flexibility and Ease of Use: Manage complex function dependencies in a clear, intuitive way with this lightweight yet powerful tool.

:test_tube: How does it work?

pipefunc provides a Pipeline class that you use to define your function pipeline. You add functions to the pipeline using the pipefunc decorator, which also lets you specify a function's output name and dependencies. Once your pipeline is defined, you can execute it for specific output values, simplify it by combining functions with the same root arguments, visualize it as a directed graph, and profile the resource usage of the pipeline functions. For more detailed usage instructions and examples, please check the usage example provided in the package.

Here is a simple example usage of pipefunc to illustrate its primary features:

from pipefunc import pipefunc, Pipeline

# Define three functions that will be a part of the pipeline
@pipefunc(output_name="c")
def f_c(a, b):
    return a + b

@pipefunc(output_name="d")
def f_d(b, c):
    return b * c

@pipefunc(output_name="e")
def f_e(c, d, x=1):
    return c * d * x

# Create a pipeline with these functions
funcs = [f_c, f_d, f_e]
pipeline = Pipeline(funcs, profile=True)

# You can access and call these functions using the func method
h_d = pipeline.func("d")
assert h_d(a=2, b=3) == 15

h_e = pipeline.func("e")
assert h_e(a=2, b=3, x=1) == 75
assert h_e(c=5, d=15, x=1) == 75

# Visualize the pipeline
pipeline.visualize()

# Get all possible argument mappings for each function
all_args = pipeline.all_arg_combinations()
print(all_args)

# Show resource reporting (only works if profile=True)
pipeline.resources_report()

This example demonstrates defining a pipeline with f_c, f_d, f_e functions, accessing and executing these functions using the pipeline, visualizing the pipeline graph, getting all possible argument mappings, and reporting on the resource usage. This basic example should give you an idea of how to use pipefunc to construct and manage function pipelines.

:notebook: Jupyter Notebook Example

See the detailed usage example and more in our example.ipynb.

:computer: Installation

Install the latest stable version from conda (recommended):

conda install pipefunc

or from PyPI:

pip install "pipefunc[plotting]"

or install main with:

pip install -U https://github.com/basnijholt/pipefunc/archive/main.zip

or clone the repository and do a dev install (recommended for dev):

git clone git@github.com:basnijholt/pipefunc.git
cd pipefunc
pip install -e ".[dev,test,plotting]"

:hammer_and_wrench: Development

We use pre-commit to manage pre-commit hooks, which helps us ensure that our code is always clean and compliant with our coding standards. To set it up, install pre-commit with pip and then run the install command:

pip install pre-commit
pre-commit install

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

pipefunc-0.5.0.tar.gz (43.7 kB view details)

Uploaded Source

Built Distribution

pipefunc-0.5.0-py3-none-any.whl (36.0 kB view details)

Uploaded Python 3

File details

Details for the file pipefunc-0.5.0.tar.gz.

File metadata

  • Download URL: pipefunc-0.5.0.tar.gz
  • Upload date:
  • Size: 43.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for pipefunc-0.5.0.tar.gz
Algorithm Hash digest
SHA256 5bbdda47a67ff6c043d1237ce3b28a8d5a6c732c3d3d3e8ab66e1bc499ed31cb
MD5 51fab8286884e36b462a50beb6bfa4e8
BLAKE2b-256 31625065159f201e48fd5e79d29e92a9a66d51d2c5a5642b1ea162fc8ef28240

See more details on using hashes here.

File details

Details for the file pipefunc-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: pipefunc-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 36.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for pipefunc-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 92ae6edcc973a390e589f3b4d7eefa6748cd7f92501bd60bc7c7e22f17a6849b
MD5 a0b0b447f7965a9ec74058a42165a8a9
BLAKE2b-256 8fa9521e9035556d9f724cb64e5a89987ed4f6802bbbd829fb94750e8452b65f

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