Package: py-pipelines
py-pipelinespipeline in python3Install via pip$pip3installpy-pipelinesClone this repository and local install$pip3install--upgrade.Run test$python3-munittest-vtests/main.pypipelinesAll functions accept the return of the previous one as their first parameter.ExamplesSimple pipelinecreate a pipeline with functionsdefpipeline(input:Any=None,pipe:Union[List[Callable],List[Union[List,Callable]]]=[])->Any:Examplefrompypipelinesimportpipelinedefone(input):returninput+" ONE "deftwo(input):returninput+" TWO "defthree(input,*args):returninput+" THREE "+"".join(args)deffour(input,a,b,c):returninput+" FOUR "+f"{a}"+f"{b}"+f"{c}"if__name__=="__main__":result=pipeline(input="TEST ",pipe=[one,two,[three," DD "," EE "," FF "],# function with paramiters[four," XX "," YY "," ZZ "]# function with paramiters])print(result)$python3main.pyTESTONETWOTHREEDDEEFFFOURXXYYZZSimple async pipelineCreate a pipeline with async functionsasyncdefasyncpipeline(input:Any=None,pipe:Union[List[Callable],List[Union[List,Callable]]]=[])->Any:Examplefrompypipelinesimportasyncpipelineimportasyncioasyncdefasyncone(input):returninput+" ONE "asyncdefasynctwo(input):returninput+" TWO "asyncdefasyncthree(input,*args):returninput+" THREE "+"".join(args)asyncdefasyncfour(input,a,b,c):returninput+" FOUR "+f"{a}"+f"{b}"+f"{c}"if__name__=="__main__":result=asyncio.run(asyncpipeline(input="TEST ",pipe=[asyncone,asynctwo,[asyncthree," DD "," EE "," FF "],[asyncfour," XX "," YY "," ZZ "]]))print(result)$python3main.pyTESTONETWOTHREEDDEEFFFOURXXYYZZSimple event loop pipelineCreate a event loop pipeline with functions and run a callback when pipeline finishdefeventlooppipeline(input:Any=None,pipe:Union[List[Callable],List[Union[List,Callable]]]=[],callback:Union[Callable,None]=None)->None:Examplefrompypipelinesimporteventlooppipelinefromtimeimportsleepdefone(input):returninput+" ONE "deftwo(input):returninput+" TWO "defthree(input,*args):returninput+" THREE "+"".join(args)deffour(input,a,b,c):returninput+" FOUR "+f"{a}"+f"{b}"+f"{c}"deftwoSleep(input):sleep(2)returninput+" BB (sleep 2) "defcallback(input):print("CALLBACK",input)if__name__=="__main__":eventlooppipeline(input="ciao",pipe=[one,two,twoSleep,[three," DD "," EE "," FF "],[four," XX "," YY "," ZZ "]],callback=callback)print("Event loop running...")$python3main.pyEventlooprunning...
CALLBACKciaoONETWOBB(sleep2)THREEDDEEFFFOURXXYYZZSimple event loop async pipelineCreate a event loop pipeline with async functions and run a callback when pipeline finishdefasynceventlooppipeline(input:Any=None,pipe:Union[List[Callable],List[Union[List,Callable]]]=[],callback:Union[Callable,None]=None)->None:Examplefrompypipelinesimportasynceventlooppipelinefromtimeimportsleepasyncdefasyncone(input):returninput+" ONE "asyncdefasynctwo(input):returninput+" TWO "asyncdefasyncthree(input,*args):returninput+" THREE "+"".join(args)asyncdefasyncfour(input,a,b,c):returninput+" FOUR "+f"{a}"+f"{b}"+f"{c}"asyncdefasynctwoSleep(input):sleep(2)returninput+" BB (async sleep 1) "defcallback(input):print("CALLBACK",input)if__name__=="__main__":asynceventlooppipeline(input="TEST ",pipe=[asyncone,asynctwo,asynctwoSleep,[asyncthree," DD "," EE "," FF "],[asyncfour," XX "," YY "," ZZ "]],callback=callback)print("Event loop running...")$python3main.pyEventlooprunning...
CALLBACKTESTONETWOBB(asyncsleep1)THREEDDEEFFFOURXXYYZZ