Schedula
Schedula is a dynamic flow-based programming environment for Python that automatically handles the control flow of programs. It produces a plan that dispatches calls based on a graph of functions, satisfying data dependencies. The library helps to define and execute dataflow execution models, extract sub-models, and can be used to deploy web API services. It is currently at version 1.6.15 and is actively maintained with regular updates.
Common errors
-
ModuleNotFoundError: No module named 'schedula'
cause The 'schedula' package has not been installed in your current Python environment or the environment where it was installed is not active.fixRun `pip install schedula` in your terminal to install the package, or activate the correct virtual environment if you've already installed it. -
AttributeError: 'Dispatcher' object has no attribute 'plot' (or 'web', 'to_server', etc.)
cause You are attempting to use a feature that is part of an optional 'extra' (e.g., `plot`, `web`) without having installed `schedula` with that specific extra.fixInstall the library with the required extra. For example, to enable plotting, use `pip install 'schedula[plot]'`. For all extras, use `pip install 'schedula[all]'`. -
FileNotFoundError: [Errno 2] No such file or directory: 'dot' (when using plot functionality)
cause The `plot` functionality in `schedula` relies on the Graphviz command-line tools, specifically the `dot` executable. This error indicates that `dot` is not found in your system's PATH.fixInstall the Graphviz system package (e.g., via your OS package manager or from graphviz.org/download/) and ensure its installation directory, containing `dot`, is added to your system's PATH environment variable.
Warnings
- gotcha Many advanced functionalities (like plotting, web API generation, or specific parallel execution strategies) are provided via 'extras'. These must be explicitly installed using `pip install 'schedula[extra_name]'` or `pip install 'schedula[all]'`.
- gotcha The 'plot' extra, which enables visualizing your dataflow models, relies on the external Graphviz system library. Installing `schedula[plot]` only installs the Python bindings; Graphviz itself (and its `dot` executable) must be installed separately on your operating system and be accessible in your system's PATH.
- gotcha While `schedula` supports asynchronous and parallel dispatching, there is an inherent performance cost associated with creating and managing threads/processes. For very short-duration tasks, this overhead might negate the benefits of concurrency.
Install
-
pip install schedula -
pip install 'schedula[all]'
Imports
- Dispatcher
import schedula as sh dsp = sh.Dispatcher(...)
Quickstart
import schedula as sh
# 1. Define a Dispatcher, which is the main model for your dataflow
dsp = sh.Dispatcher(name='my_simple_workflow')
# 2. Define functions and add them to the Dispatcher using the decorator
@sh.add_function(dsp, outputs=['y'])
def add_one(x):
print(f"Executing add_one with x={x}")
return x + 1
@sh.add_function(dsp, outputs=['z'])
def multiply_by_two(y):
print(f"Executing multiply_by_two with y={y}")
return y * 2
# 3. Dispatch the workflow with initial inputs and desired outputs
initial_inputs = {'x': 5}
desired_outputs = ['z']
try:
results = dsp.dispatch(inputs=initial_inputs, outputs=desired_outputs)
print(f"\nFinal result for 'z': {results['z']}")
except Exception as e:
print(f"An error occurred during dispatch: {e}")