Engine for piping generators
Project description
gengine
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file gengine-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: gengine-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.25.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2eb1553daaf30d06238275b655cc172639d1c628dda6ba346db5273688316d6b |
|
MD5 | ab7f53cd6428ea6c42028467c2938a7a |
|
BLAKE2b-256 | 2462b76ff6eac9a144e844e0b2d9bd193a0915b68c1fe303d57c673c9a0b37bd |