A simple Pipeline creator
Project description
DemPipe
Installation
A simple pip install will do :
python -m pip install DemPipe
Use
from DemPipe import PipeExecutor, Action
with PipeExecutor() as pipe:
actions = [Action(lambda x: x**2, 2), # returns 4
Action(lambda x: x+3, ctx_in='last_value', ctx_out='my_result_name'), # returns 4+3
Action(lambda x: x*2, ctx_in='my_result_name') # returns 2*7
]
result = pipe.execute(actions)
print('result:', result) # 14
print('result (from context):', pipe.context['last_value']) # 14
print('my_result_name:', pipe.context['my_result_name']) # 7
You can also use a Trigger Action for conditional Actions in the pipeline !
from DemPipe import PipeExecutor, Action, Trigger
with PipeExecutor() as pipe:
actions = [Action(lambda x: x**2, 2), # returns 4
Trigger(lambda x: x==3, # returns False -> executes the second action
Action(lambda x: x+3, ctx_in='last_value'), # ignored
Action(lambda x: x+7, ctx_in='last_value'), # returns 11
ctx_in='last_value')
]
result = pipe.execute(actions)
print('result:', result) # 11
Error Handling
In case an error occurs, you can configure an automatic e-mail to be sent with the traceback and the error message :
- Create a config file containing your credentials :
{
"mail": {
"mail_server": "smtp.gmail.com",
"mail_port": 587,
"mail_user": "${os_environ[user]}",
"mail_password": "${os_environ[password]}",
"mail_use_tls": true,
"mail_default_receiver": "${os_environ[receiver]}"
},
"pipe_name": "My Pipe"
}
- Specify config_file to the PipeExecutor
from DemPipe import PipeExecutor, Action
with PipeExecutor(config_file='ConfigsFolder.MyConfig') as pipe:
pipe.execute(Action(lambda x: x/0, 2)) # raises ZeroDivisionException
Other Types of actions
In addition to Trigger and Action there exist other kinds of actions :
-
ContextSetter: Makes it easier to set context values :
actions = [ContextSetter(var1=5, var2="test string"), Action(lambda x: x**2, ctx_in='var1')] print(pipe.execute(actions)) # 25 actions = [ContextSetter(lambda c: {'var1': c['var2'] * 3}, var2=4), Action(lambda x: x**2, ctx_in='variable1')] print(pipe.execute(actions)) # 144
-
Procedure: Same as an action but doesn't update the current context with its return value :
actions = [ContextSetter(last_value=3), Procedure(lambda x: x**2, ctx_in='last_value'), Action(lambda x: x + 2, ctx_in='last_value')] print(pipe.execute(actions)) # 5
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
DemPipe-0.0.2.tar.gz
(6.3 kB
view details)
Built Distribution
DemPipe-0.0.2-py3-none-any.whl
(11.6 kB
view details)
File details
Details for the file DemPipe-0.0.2.tar.gz
.
File metadata
- Download URL: DemPipe-0.0.2.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0.post20200309 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4dbab86caf985cff5d3d588fa217d0b5705a05da9b4fb607edd92dcae16b892 |
|
MD5 | f45d8750fd73dcdf0b7a79941c91e696 |
|
BLAKE2b-256 | 28dffa4eee020c85aba7ed6c797d3771a2903bd8a7c7bd6592c6b2a0a2b570e8 |
File details
Details for the file DemPipe-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: DemPipe-0.0.2-py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0.post20200309 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10bb38eedce2c6c7e980307ca53ab3e32f9eeae5d6b617fd7d938e83ba4415f1 |
|
MD5 | 82d71983b9ff16fb07eb8b61a5563b2b |
|
BLAKE2b-256 | b745fa48e278b50f890a6964d8e8c85dc6263adb14a7b3f29101b6489aca04a2 |