Skip to content

Latest commit

 

History

History
68 lines (47 loc) · 2.61 KB

File metadata and controls

68 lines (47 loc) · 2.61 KB

gengine

Version PyPI - Version PyPI - Python Version
Project GitHub License PyPI - Status PyPI - Format PyPI - Implementation
CI GitHub Actions Workflow Status
Code PyPI - Types Checked with mypy Linting: Ruff Code style: black

Engine for piping generators

Table of Contents

About

gengine (short for generator engine) is a pipeline or workflow engine for iterating over generators within a pipe and passing the output to the following generators.

This makes it a perfect fit for pipeline oriented approaches where you don't want to write the iteration logic manually.

Installation

pip install gengine

Usage

From a technical perspective, a gengine pipeline is just an ordered list of callables. Each callable implements a generator pattern (yield) or simply returns an output (return). gengine iterates over all outputs of each callable in the list and makes sure that every output is forwarded through the whole pipeline. NoneType is ignored and not forwarded (this is the reason why it is mandatory to pass an input to GenGine.run, even if the first callable doesn't use it). Each callable must accept exactly one parameter.

from gengine import GenGine

def my_gen(_inp):
    for j in range(10):
        yield j

def my_add(inp):
    return inp+2

def my_mul(inp):
    for i in range(3):
        yield inp*i

def my_filter(inp):
    if inp%2 == 0:
        return None
    else:
        return inp

g = GenGine([my_gen, my_add, my_mul, my_filter])

for el in g.run(1):
    print(el)

License

gengine is distributed under the terms of the MIT license.