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
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 Distribution
Built Distribution
File details
Details for the file easy-pipeline-0.0.1.tar.gz
.
File metadata
- Download URL: easy-pipeline-0.0.1.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 840007b921428b07f1f8cb5db06b1021537fb70354b6abca28bcff793e620429 |
|
MD5 | 76bffc8f8c9e5a83ddf3dfbc48bff7e8 |
|
BLAKE2b-256 | 83121584ffcabed7cb1296f61719cb45a2c358add733471e1c10010eb819e7aa |
File details
Details for the file easy_pipeline-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: easy_pipeline-0.0.1-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18bb85f0a8aba8e9d53f1f97f18dbceb35c8b0b3d86862b54f133be9f97044c4 |
|
MD5 | 3414fcdb2f53b966068f9beb06a6e94d |
|
BLAKE2b-256 | cf28738b7100b721e3e4bf138a1f7d0a8da2c9fa3fe296a531b5368f872d5d35 |