Skip to content

dotflow-io/dotflow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Welcome to dotflow

GitHub Org's stars GitHub last commit PyPI PyPI - Python Version PyPI - Downloads

This is a very simple library that is still in the early stages of development. The main goal of this tool is to create a simple and secure workflow for executing any type of task. The library's API design was made to make it easy to add tasks and control their execution. To keep it simple, just instantiate the DotFlow class, use the add method, and the start method to begin execution.

Start with the basics here.

Table of Contents

Click to expand

Getting Help

We use GitHub issues for tracking bugs and feature requests and have limited bandwidth to address them. If you need anything, I ask you to please follow our templates for opening issues or discussions.

Getting Started

Install

To install Dotflow, run the following command from the command line:

With Pip

pip install dotflow

With Poetry

poetry add dotflow

A Simple Example

The simplest file could look like this:

from dotflow import DotFlow, action

def my_callback(*args, **kwargs):
    print(args, kwargs)

@action
def my_task_x():
    print("task")

@action(retry=5)
def my_task_y():
    print("task")

workflow = DotFlow()

workflow.task.add(step=my_task_x, callback=my_callback)
workflow.task.add(step=my_task_y, callback=my_callback)

workflow.start()

First Steps

Import

Start with the basics, which is importing the necessary classes and methods. (DotFlow, action)

from dotflow import DotFlow, action

Callback function

Create a my_callback function to receive execution information of a task. It is not necessary to include this function, as you will still have a report at the end of the execution in the instantiated object of the DotFlow class. This my_callback function is only needed if you need to do something after the execution of the task, for example: sending a message to someone, making a phone call, or sending a letter. More details

def my_callback(*args, **kwargs):
    print(args, kwargs)

Task function

Now, create the function responsible for executing your task. It's very simple; just use the action decorator above the function, and that's itβ€”you've created a task. If necessary, you can also add the parameter called retry to set the maximum number of execution attempts if the function fails. More details

@action(retry=5)
def my_task_x():
    print("task")

DotFlow Class

Instantiate the DotFlow class in a workflow variable to be used in the following steps. More details.

workflow = DotFlow()

Add Task

Now, simply add the my_task_x and my_callback functions you created earlier to the workflow using the code below. This process is necessary to define which tasks will be executed and the order in which they will run. The execution order follows the sequence in which they were added to the workflow. More details

  • Adding one step at a time:
workflow.task.add(step=my_task_x, callback=my_callback)
workflow.task.add(step=my_task_y, callback=my_callback)
  • Adding multiple steps at the same time:
workflow.task.add(step=[my_task_x, my_task_y], callback=my_callback)
  • Adding a step with the module path:
workflow.task.add(step="module.task.my_task_x", callback=my_callback)

Start

Finally, just execute the workflow with the following code snippet. More details

workflow.start()

CLI

Simple Start

dotflow start --step examples.cli_with_mode.simple_step

With Initial Context

dotflow start --step examples.cli_with_initial_context.simple_step --initial-context abc

With Callback

dotflow start --step examples.cli_with_callback.simple_step --callback examples.cli_with_callback.callback

With Mode

dotflow start --step examples.cli_with_mode.simple_step --mode sequential
dotflow start --step examples.cli_with_mode.simple_step --mode background

More Examples

Example
01 cli_with_callback
02 cli_with_initial_context
03 cli_with_mode
04 cli_with_output_context
05 cli_with_path
06 simple_cli
07 simple_class_workflow
08 simple_function_workflow_with_error
09 simple_function_workflow
10 step_class_result_context
11 step_class_result_storage
12 step_class_result_task
13 step_function_result_context
14 step_function_result_storage
15 step_function_result_task
16 step_with_initial_context
17 step_with_many_contexts
18 step_with_previous_context
19 workflow_keep_going_true
20 workflow_step_callback
21 workflow_with_callback_failure
22 workflow_with_callback_success
23 workflow_with_retry

Commit Style

  • βš™οΈ FEATURE
  • πŸ“ PEP8
  • πŸ“Œ ISSUE
  • πŸͺ² BUG
  • πŸ“˜ DOCS
  • πŸ“¦ PyPI
  • ❀️️ TEST
  • ⬆️ CI/CD
  • ⚠️ SECURITY

License

GitHub License

This project is licensed under the terms of the MIT License.