yaml_workflow.tasks¶
yaml_workflow.tasks
¶
Task modules for the YAML Workflow Engine.
This package contains various task modules that can be used in workflows. Each module provides specific functionality that can be referenced in workflow YAML files.
Classes¶
TaskConfig
¶
Configuration class for task handlers with namespace support.
Source code in src/yaml_workflow/tasks/config.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
Attributes¶
context: Dict[str, Any]
property
¶
Read-only access to the execution context.
processed_inputs: Dict[str, Any]
property
writable
¶
Access to processed (template-resolved) inputs.
Functions¶
get_available_variables() -> Dict[str, List[str]]
¶
Get available variables by namespace.
Returns:
| Type | Description |
|---|---|
Dict[str, List[str]]
|
Dict[str, List[str]]: Available variables in each namespace |
Source code in src/yaml_workflow/tasks/config.py
get_variable(name: str, namespace: Optional[str] = None) -> Any
¶
Get a variable with namespace support.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Variable name |
required |
namespace
|
Optional[str]
|
Optional namespace (args, env, steps) |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Variable value if found |
Source code in src/yaml_workflow/tasks/config.py
process_inputs() -> Dict[str, Any]
¶
Process task inputs with template resolution.
Recursively processes all string values in the inputs dictionary, including nested dictionaries and lists.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict[str, Any]: Processed inputs with resolved templates |
Source code in src/yaml_workflow/tasks/config.py
Functions¶
add_numbers(a: float, b: float) -> float
¶
Add two numbers together.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
First number |
required |
b
|
float
|
Second number |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Sum of the numbers |
append_file_task(config: TaskConfig) -> Optional[Dict[str, Any]]
¶
Append content to a file.
Source code in src/yaml_workflow/tasks/file_tasks.py
batch_task(config: TaskConfig) -> Dict[str, Any]
¶
Process a batch of items using specified task configuration.
This task processes a list of items in parallel chunks using the specified task configuration. Each item is passed to the task as an argument.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
TaskConfig
|
TaskConfig object containing: - items: List of items to process - task: Task configuration for processing each item - arg_name: Name of the argument to use for each item (default: "item") - chunk_size: Optional size of chunks (default: 10) - max_workers: Optional maximum worker threads |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict containing: - processed: List of successfully processed items - failed: List of failed items with errors - results: List of processing results - stats: Processing statistics |
Example YAML usage
Source code in src/yaml_workflow/tasks/batch.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
create_greeting(name: str, context: Dict[str, Any]) -> str
¶
Create a greeting message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name to greet |
required |
context
|
Dict[str, Any]
|
Template context |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Greeting message |
Raises:
| Type | Description |
|---|---|
TemplateError
|
If template resolution fails |
Source code in src/yaml_workflow/tasks/basic_tasks.py
echo(message: str) -> str
¶
Echo back the input message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Message to echo |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The input message |
fail(message: str = 'Task failed') -> None
¶
A task that always fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Error message |
'Task failed'
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
Always raises this error |
get_task_handler(name: str) -> Optional[TaskHandler]
¶
Get a task handler by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Task name |
required |
Returns:
| Type | Description |
|---|---|
Optional[TaskHandler]
|
Optional[TaskHandler]: Task handler if found |
Source code in src/yaml_workflow/tasks/__init__.py
hello_world(name: str = 'World') -> str
¶
A simple hello world function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name to include in greeting. Defaults to "World". |
'World'
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The greeting message |
Source code in src/yaml_workflow/tasks/basic_tasks.py
http_request_task(config: TaskConfig) -> Dict[str, Any]
¶
Make an HTTP request to a URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
TaskConfig
|
Task configuration with namespace support |
required |
Inputs
url (str): Target URL. Required.
method (str): HTTP method. Default GET.
headers (dict): Extra request headers. Default {}.
body (str | dict | bytes): Request body. When a dict is provided it is
serialised to JSON and Content-Type: application/json is set
automatically (unless already present in headers).
timeout (int | float): Request timeout in seconds. Default 30.
token (str): Shorthand Bearer token. Sets
Authorization: Bearer <token>. Ignored when auth is also
provided.
auth (dict): Authentication configuration. Supports the following
types:
bearer::
auth:
type: bearer
token: "{{ env.API_TOKEN }}"
# OR read from environment:
token_env: API_TOKEN
api_key::
auth:
type: api_key
key: "{{ env.API_KEY }}"
header: X-API-Key # optional, default: X-API-Key
basic::
auth:
type: basic
username: "{{ env.API_USER }}"
password: "{{ env.API_PASS }}"
verify_ssl (bool): Verify the server's TLS certificate. Default
True. Set to False to disable certificate verification
(equivalent to curl --insecure).
retry (dict): Retry configuration::
retry:
max_attempts: 3 # total attempts, default: 1
delay: 1.0 # seconds between retries, default: 1.0
status_codes: [429, 503] # retry on these codes,
# default: [429, 500, 502, 503, 504]
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict[str, Any]: Response with keys |
Dict[str, Any]
|
|
Raises:
| Type | Description |
|---|---|
TaskExecutionError
|
If the request fails or authentication config is invalid. |
Source code in src/yaml_workflow/tasks/http_tasks.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
join_strings(*strings: str, separator: str = ' ') -> str
¶
Join multiple strings together.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*strings
|
str
|
Variable number of strings to join |
()
|
separator
|
str
|
String to use as separator. Defaults to space. |
' '
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Joined string |
Source code in src/yaml_workflow/tasks/basic_tasks.py
noop_task(config: TaskConfig) -> Dict[str, Any]
¶
No-operation task that returns its inputs and metadata.
This task is useful for testing and demonstrating the workflow engine's features without performing any actual operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
TaskConfig
|
Task configuration with: - should_fail: Optional boolean to simulate task failure |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict[str, Any]: Task inputs and metadata |
Raises:
| Type | Description |
|---|---|
TaskExecutionError
|
If should_fail is True (via handle_task_error) |
Source code in src/yaml_workflow/tasks/noop.py
notify_task(config: TaskConfig) -> Dict[str, Any]
¶
Send a notification via one of several supported channels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
TaskConfig
|
Task configuration with namespace support. |
required |
Inputs
channel (str): Notification channel. Required. One of webhook,
log, slack, file.
webhook channel::
channel: webhook
url: "https://hooks.example.com/..."
message: "Workflow completed"
method: POST # optional, default POST
headers: # optional extra headers
X-Custom: value
payload: # optional; used as-is; otherwise {"text": message}
text: "..."
log channel::
channel: log
message: "Step completed"
level: info # debug|info|warning|error, default: info
file: "notify.log" # optional; appended as plain text
slack channel::
channel: slack
webhook_url: "{{ env.SLACK_WEBHOOK_URL }}"
message: "{{ workflow.name }} finished"
username: "yaml-workflow" # optional
icon_emoji: ":robot_face:" # optional
color: good # optional: good|warning|danger|#hex
file channel::
channel: file
file: "notifications.jsonl"
message: "Completed"
append: true # default true
format: jsonl # jsonl|text, default: jsonl
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict[str, Any]: |
Raises:
| Type | Description |
|---|---|
TaskExecutionError
|
If the notification cannot be delivered. |
Source code in src/yaml_workflow/tasks/notify_tasks.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
print_vars_task(config: TaskConfig) -> dict
¶
Prints selected variables from the context for debugging.
Source code in src/yaml_workflow/tasks/python_tasks.py
read_file_task(config: TaskConfig) -> Optional[Dict[str, Any]]
¶
Read content from a file.
Source code in src/yaml_workflow/tasks/file_tasks.py
read_json_task(config: TaskConfig) -> Optional[Dict[str, Any]]
¶
Task handler for reading JSON files.
Source code in src/yaml_workflow/tasks/file_tasks.py
read_yaml_task(config: TaskConfig) -> Optional[Dict[str, Any]]
¶
Task handler for reading YAML files.
Source code in src/yaml_workflow/tasks/file_tasks.py
register_task(name: Optional[str] = None) -> Callable[..., Callable[[TaskConfig], R]]
¶
Decorator to register a function as a workflow task.
Source code in src/yaml_workflow/tasks/__init__.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
render_template(config: TaskConfig) -> Dict[str, Any]
¶
Render a template and save it to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
TaskConfig
|
Task configuration object |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict[str, Any]: Dictionary containing the path to the output file |
Raises:
| Type | Description |
|---|---|
TaskExecutionError
|
If template resolution fails or file cannot be written (via handle_task_error) |
Source code in src/yaml_workflow/tasks/template_tasks.py
shell_task(config: TaskConfig) -> Dict[str, Any]
¶
Run a shell command with namespace support.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
TaskConfig
|
Task configuration with namespace support |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict[str, Any]: Command execution results |
Raises:
| Type | Description |
|---|---|
TaskExecutionError
|
If command execution fails or template resolution fails |
Source code in src/yaml_workflow/tasks/shell_tasks.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | |
write_file_task(config: TaskConfig) -> Optional[Dict[str, Any]]
¶
Write content to a file.
Source code in src/yaml_workflow/tasks/file_tasks.py
write_json_task(config: TaskConfig) -> Optional[Dict[str, Any]]
¶
Write JSON data to a file.
Source code in src/yaml_workflow/tasks/file_tasks.py
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 | |
write_yaml_task(config: TaskConfig) -> Optional[Dict[str, Any]]
¶
Write YAML data to a file.