dags is a Python library for creating executable directed acyclic graphs (DAGs) from interdependent functions. It automatically determines the execution order based on function signatures and enables efficient composition of complex computational pipelines.
Key Features¶
Automatic dependency resolution: Functions are ordered based on their parameter names matching other functions’ names
Function composition: Combine multiple functions into a single callable
Tree structures: Work with nested dictionaries using qualified names
Signature manipulation: Rename arguments and manage function signatures
Quick Example¶
The following example defines three functions where each depends on the previous one, then combines them into a single callable:
import dags
def a(x):
return x**2
def b(a):
return a + 1
def c(a, b):
return a + b
combined = dags.concatenate_functions(
functions={"a": a, "b": b, "c": c},
targets=["c"],
return_type="dict",
)
combined(x=5){'c': 51}dags resolves dependencies by matching parameter names to function names: function b has a parameter called a, so dags knows to run function a first and pass its result to b. Any parameter that doesn’t match a function name (like x) becomes an input to the combined function.
The key is that you can build the combined function at runtime, which allows you to compose a computational pipeline in a way that you do not need to specify in advance, or in a multitude of ways. It has proven very helpful in a framework to solve life cycle models (pylcm) and to model the German taxes and transfers system (ttsim / gettsim).
Installation¶
pip install dagsOr with conda:
conda install -c conda-forge dags