flowrunner.core package
Subpackages
Submodules
flowrunner.core.base module
Module with base classes for use in other modules
Node: A class for containing functions, with the function name, actual function reference, docstring and its next functions GraphOptions: A class for all the options to be given to Graph, a collection of start, middle and end nodes Graph: A class containing an arranged collection of Nodes from start, middle, end in Graph.levels
- class flowrunner.core.base.Graph(graph_options: GraphOptions)
Bases:
objectA class containing an arranged collection of Nodes from start, middle, end in Graph.levels
- graph_options
An instance of GraphOptions class
- start
A list of start nodes, we take this from GraphOptions.start, A list of nodes decorated with @start
- middle_nodes
A list of middle nodes, we take this from GraphOptions.middle_nodes, A list of nodes decorated with @step only
- end
A list of end nodes, we take this from GraphOptions.end, A list of nodes decorated with @end
- nodes
A list of all the nodes start + middle_nodes + end
- node_map
A dict of {node.name: node} for reference for later
- levels
A list containing the iteration order for methods from start -> middle_nodes -> end
- graph_options: GraphOptions
- class flowrunner.core.base.GraphOptions(base_flow: Type)
Bases:
objectA class for all the options to be given to Graph, a collection of start, middle and end nodes
We only take base_flow argument, the rest of the attributes are assigned in the __post_init__. We iterate over all the methods in the class and arrange them according to ‘start’, ‘step’, ‘end’ as per the decorators.
- base_flow
A subclass of BaseFlow
- Type:
Type
- functions
A dictionary of {‘test_1’: <function Test.test_1 at 0x000002390259E9D0>} using inbuilt __dict__ method
- middle_nodes
A list of middle nodes i.e methods with only ‘step’ and no ‘start’ and ‘end’ decorator
- start
A list of middle nodes i.e methods with ‘start’ decorator
- end
A list of middle nodes i.e methods with ‘end’ decorator
- base_flow_instance
An instance of base_flow we use later to run flows
- base_flow: Type
- class flowrunner.core.base.Node(name: str, function_reference: callable)
Bases:
objectA class for containing functions, with the function name, actual function reference, docstring and its next functions
- name
A str value of the name of the function __name__
- Type:
str
- function_reference
The actual function or callable
- Type:
callable
- next
None by default, list value of what is next node, assigned in __post_init__
- docstring
Docstring of method assigned in __post_init__
- function_reference: callable
- name: str
flowrunner.core.decorators module
Module for decorators
- class flowrunner.core.decorators.Step(func: Callable, next: str | list | None = None)
Bases:
objectStep is a decorator class to convert any function to a ‘step’ function and have a next
- flowrunner.core.decorators.end(func: Callable) Callable
This decorator indicates the end of a flow
- flowrunner.core.decorators.start(func: Callable) Callable
This decorator indicates the start of a flow
- flowrunner.core.decorators.step(function: Callable = None, next: List | str = None)
This decorator indicates a step in the function We add a 3 attributes to it is_step, name, next
flowrunner.core.helpers module
Modules for any helpers for any base.py classes
GraphValidator: A class for validating any subclass of BaseFlow DAGGenerator: A class for creating dags based on a subclass of BaseFlow
- class flowrunner.core.helpers.DAGGenerator
Bases:
objectClass to flowrunner DAGs based on Flow
- classmethod dag(flow_instance, save_file: bool = False, path: str = None, description: bool = True) str
Class method to generate DAG from Flow in the form of html output
We use the Flow class to generate a flowchart and return the html content. This method can be used to save locally or use the html content elsewhere
- Parameters:
flow_instance – An instance of BaseFlow subclass object
save_file – Bool value to save file, defaults to False
path – A path to save file
description – Bool value of saving description of class
- Returns:
The html data containing the flow diagram
- Return type:
content
- classmethod display(flow_instance, description: bool = True) None
Class method to display the DAG of the Flow
This method only works in IPython style notebooks. Does not work in script This method displays the flowchart of the Flow based the Flow class itself.
- Args
flow_instance: An instance of subclass of BaseFlow description: A bool value of descriptive, descriptive on adds docstring to DAG
- Returns:
display the flowchart of the Flow
- Return type:
None
- class flowrunner.core.helpers.GraphValidator(graph: Graph)
Bases:
objectThis class is used to validate any Graph
Each of the method represents a seperate check of the validation suite to be conducted on the self.graph attribute. All the methods a tuple of (test_result, output_message) where test_result will be a True/False bool and output_message is a string value of the output message.
- graph
An instance of Graph class to be checked
- check_step_not_included_next() Tuple[bool, str]
Method to validate that a step mentioned is used in the next.
We find any step that is not mentioned in a next that is not start or end, meaning a mid starting node
- Returns:
A tuple of (test_result, output_message) where test_result will be a True/False bool and output_message is a string value of the output message.
- get_validation_suite()
Define validation suite, more methods need to be added to validation suite list
Any new validation method has to be added to validation_suite so that it can be called on validation checks.
- Returns:
- A dict object containing the list of GraphValidator methods to be used to validate
base_flow subclasses
- Return type:
validation_suite
- run_validations(terminal_output: bool = True)
Method to run all validation methods We iterate through the validation suite for each method and check the output. Output is always in the form of Tuple[bool, str]. With bool for Pass or Fail and str being the output message
- Parameters:
terminal_output – An optional bool argument for whether to show the output in terminal
- Returns:
Echo of output {✅} or {❌} if passed or failed respectively with message
- run_validations_raise_error(terminal_output: bool = True)
Method to run all validation methods but we raise an error if anything fails We iterate through the validation suite for each method and check the output. Output is always in the form of Tuple[bool, str]. With bool for Pass or Fail and str being the output message
- Parameters:
terminal_output – An optional bool argument for whether to show the output in terminal
- Returns:
Echo of output {✅} or {❌} if passed or failed respectively with message
- Raises:
InvalidFlowException – If any validation check failed
- validate_length_end_nodes() Tuple[bool, str]
Method to validate the length of end nodes.
We make sure that there is atleast one end node
- Returns:
- A tuple of (test_result, output_message) where test_result will be a True/False bool and output_message is a string value
of the output message.
- validate_length_middle_nodes() Tuple[bool, str]
Method to validate the length of middle nodes.
We make sure that there is atleast one start node
- Returns:
- A tuple of (test_result, output_message) where test_result will be a True/False bool and output_message is a string value
of the output message.
- validate_length_start_nodes() Tuple[bool, str]
Method to validate the length of start nodes.
We make sure that there is atleast one start node
- Returns:
- A tuple of (test_result, output_message) where test_result will be a True/False bool and output_message is a string value
of the output message.
- validate_middle_next_nodes() Tuple[bool, str]
Method to check that the middle nodes specified are valid.
We make sure that each of the nodes specified has a next
- Returns:
- A tuple of (test_result, output_message) where test_result will be a True/False bool and output_message is a string value
of the output message
- validate_start_next_nodes() Tuple[bool, str]
Method to check that the start nodes specified are valid.
We make sure that each of the nodes specified has a next
- Returns:
- A tuple of (test_result, output_message) where test_result will be a True/False bool and output_message is a string value
of the output message