API Reference¶
Auto-generated API documentation from source code.
Core Module¶
Stardag: Declarative and composable DAG framework for Python.
Stardag provides a clean Python API for representing persistently stored assets as a declarative Directed Acyclic Graph (DAG).
Basic usage::
import stardag as sd
@sd.task
def get_range(limit: int) -> list[int]:
return list(range(limit))
@sd.task
def get_sum(integers: sd.Depends[list[int]]) -> int:
return sum(integers)
task = get_sum(integers=get_range(limit=10))
sd.build(task)
print(task.output().load()) # 45
Core components:
- :func:
task- Decorator for creating tasks from functions - :class:
Task- Base class for all tasks - :class:
AutoTask- Task with automatic filesystem targets - :class:
Depends- Dependency injection type annotation - :func:
build- Execute task and its dependencies
See https://docs.stardag.com for full documentation.
TODO: Expand docstrings for all public API components.
TaskLoads
module-attribute
¶
TaskLoads = Annotated[
Task[LoadableTarget[LoadedT_co]], Polymorphic()
]
TaskStruct
module-attribute
¶
target_factory_provider
module-attribute
¶
target_factory_provider = resource_provider(
type_=TargetFactory, default_factory=TargetFactory
)
Task
¶
AutoTask
¶
Bases: Task[LoadableSaveableFileSystemTarget[LoadedT]], ABC, Generic[LoadedT]
A base class for automatically serializing task outputs.
The output of an AutoTask is a LoadableSaveableFileSystemTarget that uses a
serializer inferred from the generic type parameter LoadedT.
The output file path is automatically constructed based on the task's namespace, name, version, and unique ID and has the following structure:
[<relpath_base>/][<namespace>/]<name>/v<version>/[<relpath_extra>/]
<id>[:2]/<id>[2:4]/<id>[/<relpath_filename>].<relpath_extension>
You can override the following properties to customize the output path:
_relpath_base, _relpath_extra, _relpath_filename, and _relpath_extension.
See stardag.target.serialize.get_serializer for details on how the serializer is inferred from the generic type parameter, and how to customize it.
Example:
import stardag as sd
class MyAutoTask(sd.AutoTask[dict[str, int]]):
def run(self):
self.output().save({"a": 1, "b": 2})
my_task = MyAutoTask()
print(my_task.output())
# Serializable(../MyAutoTask/03/6f/036f6e71-1b3c-54b8-aec1-182359f1e09a.json)
print(my_task.output().serializer)
# <stardag.target.serialize.JSONSerializer at 0x1064e4710>
__map_generic_args_to_ancestor__
classmethod
¶
Map generic args from AutoTask to how they appear on an ancestor class.
This enables type compatibility checking when using AutoTask with TaskLoads. For example, AutoTask[str] maps to Task[LoadableSaveableFileSystemTarget[str]], which is compatible with TaskLoads[str] (= Task[LoadableTarget[str]]) because LoadableSaveableFileSystemTarget is a subtype of LoadableTarget.
| PARAMETER | DESCRIPTION |
|---|---|
ancestor_origin
|
The ancestor class to map args to (e.g., Task)
TYPE:
|
args
|
The generic args of this class (e.g., (str,) for AutoTask[str])
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple | None
|
The mapped args for the ancestor, or None if mapping is not applicable. |
BaseTask
¶
Bases: PolymorphicRoot
__init_subclass__
¶
Validate that subclasses implement either run() or run_aio().
Also wraps run() and run_aio() methods with precheck validation.
run
¶
Execute the task logic (sync).
Override this method for synchronous tasks. If you only override run_aio(), this method will automatically run it via asyncio.run().
| RETURNS | DESCRIPTION |
|---|---|
None | Generator[TaskStruct, None, None]
|
None for simple tasks, or a Generator yielding TaskStruct for |
None | Generator[TaskStruct, None, None]
|
tasks with dynamic dependencies (See Dynamic Dependencies Contract below). |
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If called from within an existing event loop when only run_aio() is implemented. In that case, call run_aio() directly instead. |
NotImplementedError
|
If run_aio() is an async generator (dynamic deps). Async generators cannot be automatically converted to sync generators. |
Dynamic Dependencies Contract: When a task yields dynamic dependencies via a generator, the BUILD SYSTEM guarantees that ALL yielded tasks are COMPLETE before the generator is resumed. The task can rely on this contract:
def run(self):
# Do some initial work to get info about what additional dependencies
# are needed
initial_data = "..."
# Yield deps we need to be built first
task_a = TaskA(input=initial_data)
task_b = TaskB(input=initial_data)
yield [task_a, task_b]
# CONTRACT: When we reach here, ALL deps are complete.
# We can safely access their outputs.
result_a = task_a.output().load()
result_b = task_b.output().load()
# Yield more deps if needed
task_c = TaskC(input=result_a)
yield task_c
# Again, TaskC is complete when we reach here
self.output().save(task_c.output().load() + result_b)
This contract is essential for correctness - tasks can depend on previously yielded tasks being complete before continuing execution.
run_aio
async
¶
Execute the task logic (async).
Override this method for asynchronous tasks. If you only override run(), this method will automatically delegate to it.
For dynamic dependencies, you can use 'yield' which makes this an async generator. Note that async generator methods have different type signatures that may require type: ignore comments.
| RETURNS | DESCRIPTION |
|---|---|
None | Generator[TaskStruct, None, None]
|
None for simple tasks, or a Generator/AsyncGenerator for |
None | Generator[TaskStruct, None, None]
|
tasks with dynamic dependencies. |
Dynamic Dependencies Contract
Same as run() - the build system guarantees that ALL yielded tasks are COMPLETE before the generator is resumed. See run() docstring for detailed documentation and examples.
registry_assets
¶
Return assets to be stored in the registry after task completion.
Override this method to expose rich outputs (reports, summaries, structured data) that will be viewable in the registry UI.
This method is called after the task completes successfully. It should be stateless - loading any required data from the task's target rather than relying on in-memory state.
| RETURNS | DESCRIPTION |
|---|---|
list[RegistryAsset]
|
List of registry assets (MarkdownRegistryAsset, JSONRegistryAsset, etc.) |
registry_assets_aio
¶
Asynchronously return assets to be stored in the registry after task completion.
resolve
classmethod
¶
Override PolymorphicRoot.resolve to handle AliasTask deserialization.
from_registry
classmethod
¶
Instantiate the task from the registry.
| PARAMETER | DESCRIPTION |
|---|---|
id
|
The UUID of the task to alias.
TYPE:
|
registry
|
An optional registry instance to use for loading metadata. If not
provided, the default registry from
TYPE:
|
Returns: An AliasTask instance referencing the specified task.
task
¶
build_aio
async
¶
build_aio(
tasks,
task_executor=None,
fail_mode=FAIL_FAST,
registry=None,
max_concurrent_discover=50,
global_lock_manager=None,
global_lock_config=None,
resume_build_id=None,
)
Build tasks concurrently using hybrid async/thread/process execution.
This is the main build function for production use. It: - Discovers all tasks in the DAG(s) - Schedules tasks for execution when dependencies are met - Handles dynamic dependencies via generator suspension - Supports multiple root tasks (built concurrently) - Routes tasks to async/thread/process based on ExecutionModeSelector - Manages all registry interactions (start/complete/fail task) - Optionally uses global concurrency locks for distributed execution
| PARAMETER | DESCRIPTION |
|---|---|
tasks
|
List of root tasks to build (and their dependencies) or a single root task. |
task_executor
|
TaskExecutor for executing tasks (default: HybridConcurrentTaskExecutor). Use RoutedTaskExecutor to route tasks to different executors (e.g., Modal).
TYPE:
|
fail_mode
|
How to handle task failures
TYPE:
|
registry
|
Registry for tracking builds (default: from init_registry())
TYPE:
|
max_concurrent_discover
|
Maximum concurrent completion checks during DAG discovery. Higher values speed up discovery for large DAGs with remote targets.
TYPE:
|
global_lock_manager
|
Global concurrency lock manager for distributed builds. If provided with global_lock_config.enabled=True, tasks will acquire locks before execution to ensure exactly-once execution across processes.
TYPE:
|
global_lock_config
|
Configuration for global locking behavior.
TYPE:
|
resume_build_id
|
Optional build ID to resume. If provided, continues tracking events under this existing build instead of starting a new one.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BuildSummary
|
BuildSummary with status, task counts, and build_id |
build_sequential
¶
build_sequential(
tasks,
registry=None,
fail_mode=FAIL_FAST,
dual_run_default="sync",
resume_build_id=None,
global_lock_manager=None,
global_lock_config=None,
)
Sync API for building tasks sequentially.
This is intended primarily for debugging and testing.
Task execution policy:
- Sync-only tasks: run via run()
- Async-only tasks: run via asyncio.run(run_aio()). (Does not work if called
from within an existing event loop.)
- Dual tasks: run via run() if dual_run_default=="sync" (default), else
(dual_run_default=="async") via asyncio.run(run_aio()).
| PARAMETER | DESCRIPTION |
|---|---|
tasks
|
List of root tasks to build (and their dependencies) or a single root task. |
registry
|
Registry for tracking builds
TYPE:
|
fail_mode
|
How to handle task failures
TYPE:
|
dual_run_default
|
For dual tasks, prefer sync or async execution
TYPE:
|
resume_build_id
|
Optional build ID to resume. If provided, continues tracking events under this existing build instead of starting a new one.
TYPE:
|
global_lock_manager
|
Global concurrency lock manager for distributed builds. If provided with global_lock_config.enabled=True, tasks will acquire locks before execution for "exactly once" semantics across processes.
TYPE:
|
global_lock_config
|
Configuration for global locking behavior.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BuildSummary
|
BuildSummary with status, task counts, and build_id |
build_sequential_aio
async
¶
build_sequential_aio(
tasks,
registry=None,
fail_mode=FAIL_FAST,
sync_run_default="blocking",
resume_build_id=None,
global_lock_manager=None,
global_lock_config=None,
)
Async API for building tasks sequentially.
This is intended primarily for debugging and testing.
Task execution policy:
- Sync-only tasks: runs blocking via run() in main event loop if
sync_run_default=="blocking" (default), else (sync_run_default=="thread")
in thread pool.
- Async-only tasks: run via await run_aio().
- Dual tasks: run via await run_aio().
| PARAMETER | DESCRIPTION |
|---|---|
tasks
|
List of root tasks to build (and their dependencies) or a single root task. |
registry
|
Registry for tracking builds
TYPE:
|
fail_mode
|
How to handle task failures
TYPE:
|
sync_run_default
|
For sync-only tasks, block or use thread pool
TYPE:
|
resume_build_id
|
Optional build ID to resume. If provided, continues tracking events under this existing build instead of starting a new one.
TYPE:
|
global_lock_manager
|
Global concurrency lock manager for distributed builds. If provided with global_lock_config.enabled=True, tasks will acquire locks before execution for "exactly once" semantics across processes.
TYPE:
|
global_lock_config
|
Configuration for global locking behavior.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BuildSummary
|
BuildSummary with status, task counts, and build_id |
namespace
¶
Set the task namespace for the module and any submodules.
| PARAMETER | DESCRIPTION |
|---|---|
namespace
|
The namespace to set for the module.
TYPE:
|
scope
|
The module scope, typically passed as
TYPE:
|
Usage:
```python import stardag as sd sd.namespace("my_custom_namespace", name)
class MyNamespacedTask(sd.Task[int]): a: int
def run(self):
self.output().save(self.a)
assert MyNamespacedTask.get_namespace() == "my_custom_namespace"
auto_namespace
¶
Set the task namespace for the module to the module import path.
| PARAMETER | DESCRIPTION |
|---|---|
scope
|
The module scope, typically passed as
TYPE:
|
Usage:
Build Module¶
build
¶
Build module for stardag.
This module provides functions and classes for building task DAGs.
Primary build functions: - build(): Concurrent build, recommended for real workloads from a sync context - build_aio(): Async concurrent build, recommended for real workloads from an async context or already running event loop - build_sequential(): Sync sequential build (for debugging) - build_sequential_aio(): Async sequential build (for debugging)
Task executor: - HybridConcurrentTaskExecutor: Routes tasks to async/thread/process pools
Interfaces: - TaskExecutorABC: Abstract base class for custom task executors - ExecutionModeSelector: Protocol for custom execution mode selection
Global concurrency locking: - GlobalConcurrencyLockManager: Protocol for distributed lock implementations - LockHandle: Protocol for lock handles (async context manager) - GlobalLockConfig: Configuration for global locking behavior
BuildSummary
dataclass
¶
Summary of a build execution.
__repr__
¶
Return a human-readable summary of the build.
Source code in stardag/build/_base.py
BuildExitStatus
¶
Bases: StrEnum
FailMode
¶
Bases: StrEnum
How to handle task failures during build.
| ATTRIBUTE | DESCRIPTION |
|---|---|
FAIL_FAST |
Stop the build at the first task failure.
|
CONTINUE |
Continue executing all tasks whose dependencies are met, even if some tasks have failed.
|
HybridConcurrentTaskExecutor
¶
HybridConcurrentTaskExecutor(
execution_mode_selector=None,
max_async_workers=10,
max_thread_workers=10,
max_process_workers=None,
)
Bases: TaskExecutorABC
Task executor with async, thread, and process pools.
Routes tasks to appropriate execution context based on ExecutionModeSelector. Handles generator suspension for dynamic dependencies.
Note: This executor does not handle registry calls - those are managed by the build() function. The executor only executes tasks and returns results.
For routing tasks to different executors (e.g., some to Modal, some local), use RoutedTaskExecutor to compose multiple executors.
Alternative: For fully async multiprocessing without thread pools, one could implement an AIOMultiprocessingTaskExecutor using libraries like aiomultiprocess.
| PARAMETER | DESCRIPTION |
|---|---|
execution_mode_selector
|
Callable to select execution mode per task.
TYPE:
|
max_async_workers
|
Maximum concurrent async tasks (semaphore-based).
TYPE:
|
max_thread_workers
|
Maximum concurrent thread pool workers.
TYPE:
|
max_process_workers
|
Maximum concurrent process pool workers.
TYPE:
|
Source code in stardag/build/_concurrent.py
setup
async
¶
Initialize worker pools.
Source code in stardag/build/_concurrent.py
teardown
async
¶
Shutdown worker pools.
Source code in stardag/build/_concurrent.py
submit
async
¶
Execute a task and return result.
Note: This method does not make any registry calls. The build function is responsible for calling start_task, complete_task, and fail_task.
Source code in stardag/build/_concurrent.py
TaskExecutorABC
¶
Bases: ABC
Abstract base for task executors.
Receives tasks and executes them according to some policy. The executor is responsible for: - Executing tasks in the appropriate context (async/thread/process) - Handling generator suspension for dynamic dependencies
The executor is NOT responsible for: - Dependency resolution - handled by build() - Registry calls (start_task, complete_task, etc.) - handled by build()
submit
abstractmethod
async
¶
Submit a task for execution.
| PARAMETER | DESCRIPTION |
|---|---|
task
|
The task to execute.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None | TaskStruct | Exception
|
|
None | TaskStruct | Exception
|
|
None | TaskStruct | Exception
|
|
Source code in stardag/build/_base.py
setup
abstractmethod
async
¶
build
¶
build(
tasks,
task_executor=None,
fail_mode=FAIL_FAST,
registry=None,
max_concurrent_discover=50,
global_lock_manager=None,
global_lock_config=None,
resume_build_id=None,
)
Build tasks concurrently (sync wrapper for build_aio).
This is the recommended entry point for building tasks from synchronous code. Wraps the async build_aio() function.
Note
This function cannot be called from within an already running event loop.
If you're in an async context (e.g., inside an async function, or using
frameworks like Playwright, FastAPI, etc.), use await build_aio() instead.
Source code in stardag/build/_concurrent.py
build_aio
async
¶
build_aio(
tasks,
task_executor=None,
fail_mode=FAIL_FAST,
registry=None,
max_concurrent_discover=50,
global_lock_manager=None,
global_lock_config=None,
resume_build_id=None,
)
Build tasks concurrently using hybrid async/thread/process execution.
This is the main build function for production use. It: - Discovers all tasks in the DAG(s) - Schedules tasks for execution when dependencies are met - Handles dynamic dependencies via generator suspension - Supports multiple root tasks (built concurrently) - Routes tasks to async/thread/process based on ExecutionModeSelector - Manages all registry interactions (start/complete/fail task) - Optionally uses global concurrency locks for distributed execution
| PARAMETER | DESCRIPTION |
|---|---|
tasks
|
List of root tasks to build (and their dependencies) or a single root task. |
task_executor
|
TaskExecutor for executing tasks (default: HybridConcurrentTaskExecutor). Use RoutedTaskExecutor to route tasks to different executors (e.g., Modal).
TYPE:
|
fail_mode
|
How to handle task failures
TYPE:
|
registry
|
Registry for tracking builds (default: from init_registry())
TYPE:
|
max_concurrent_discover
|
Maximum concurrent completion checks during DAG discovery. Higher values speed up discovery for large DAGs with remote targets.
TYPE:
|
global_lock_manager
|
Global concurrency lock manager for distributed builds. If provided with global_lock_config.enabled=True, tasks will acquire locks before execution to ensure exactly-once execution across processes.
TYPE:
|
global_lock_config
|
Configuration for global locking behavior.
TYPE:
|
resume_build_id
|
Optional build ID to resume. If provided, continues tracking events under this existing build instead of starting a new one.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BuildSummary
|
BuildSummary with status, task counts, and build_id |
Source code in stardag/build/_concurrent.py
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 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 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 | |
build_sequential
¶
build_sequential(
tasks,
registry=None,
fail_mode=FAIL_FAST,
dual_run_default="sync",
resume_build_id=None,
global_lock_manager=None,
global_lock_config=None,
)
Sync API for building tasks sequentially.
This is intended primarily for debugging and testing.
Task execution policy:
- Sync-only tasks: run via run()
- Async-only tasks: run via asyncio.run(run_aio()). (Does not work if called
from within an existing event loop.)
- Dual tasks: run via run() if dual_run_default=="sync" (default), else
(dual_run_default=="async") via asyncio.run(run_aio()).
| PARAMETER | DESCRIPTION |
|---|---|
tasks
|
List of root tasks to build (and their dependencies) or a single root task. |
registry
|
Registry for tracking builds
TYPE:
|
fail_mode
|
How to handle task failures
TYPE:
|
dual_run_default
|
For dual tasks, prefer sync or async execution
TYPE:
|
resume_build_id
|
Optional build ID to resume. If provided, continues tracking events under this existing build instead of starting a new one.
TYPE:
|
global_lock_manager
|
Global concurrency lock manager for distributed builds. If provided with global_lock_config.enabled=True, tasks will acquire locks before execution for "exactly once" semantics across processes.
TYPE:
|
global_lock_config
|
Configuration for global locking behavior.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BuildSummary
|
BuildSummary with status, task counts, and build_id |
Source code in stardag/build/_sequential.py
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 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 | |
build_sequential_aio
async
¶
build_sequential_aio(
tasks,
registry=None,
fail_mode=FAIL_FAST,
sync_run_default="blocking",
resume_build_id=None,
global_lock_manager=None,
global_lock_config=None,
)
Async API for building tasks sequentially.
This is intended primarily for debugging and testing.
Task execution policy:
- Sync-only tasks: runs blocking via run() in main event loop if
sync_run_default=="blocking" (default), else (sync_run_default=="thread")
in thread pool.
- Async-only tasks: run via await run_aio().
- Dual tasks: run via await run_aio().
| PARAMETER | DESCRIPTION |
|---|---|
tasks
|
List of root tasks to build (and their dependencies) or a single root task. |
registry
|
Registry for tracking builds
TYPE:
|
fail_mode
|
How to handle task failures
TYPE:
|
sync_run_default
|
For sync-only tasks, block or use thread pool
TYPE:
|
resume_build_id
|
Optional build ID to resume. If provided, continues tracking events under this existing build instead of starting a new one.
TYPE:
|
global_lock_manager
|
Global concurrency lock manager for distributed builds. If provided with global_lock_config.enabled=True, tasks will acquire locks before execution for "exactly once" semantics across processes.
TYPE:
|
global_lock_config
|
Configuration for global locking behavior.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BuildSummary
|
BuildSummary with status, task counts, and build_id |
Source code in stardag/build/_sequential.py
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 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 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 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 | |
Target Module¶
target
¶
target_factory_provider
module-attribute
¶
target_factory_provider = resource_provider(
type_=TargetFactory, default_factory=TargetFactory
)
FileSystemTarget
¶
LoadableSaveableFileSystemTarget
¶
LocalTarget
¶
TargetFactory
¶
Source code in stardag/target/_factory.py
get_target
¶
Get a file system target.
| PARAMETER | DESCRIPTION |
|---|---|
relpath
|
The path to the target, relative to the configured root path for
TYPE:
|
target_root_key
|
The key to the target root to use.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FileSystemTarget
|
A file system target. |
Source code in stardag/target/_factory.py
get_directory_target
¶
Get a directory target.
| PARAMETER | DESCRIPTION |
|---|---|
relpath
|
The path to the target, relative to the configured root path for
TYPE:
|
target_root_key
|
The key to the target root to use.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DirectoryTarget
|
A directory target. |
Source code in stardag/target/_factory.py
get_path
¶
Get the full (/"absolute") path (/"URI") to the target.
Source code in stardag/target/_factory.py
Registry Module¶
registry
¶
Task registry module for stardag.
This module provides registry implementations for tracking task execution. The main classes are:
- RegistryABC: Abstract base class defining the registry interface
- APIRegistry: Registry that communicates with the stardag-api service
- NoOpRegistry: A do-nothing registry (default when unconfigured)
- registry_provider: Resource provider for getting the configured registry
- RegistryGlobalConcurrencyLockManager: GlobalConcurrencyLockManager using Registry API
- RegistryLockHandle: LockHandle implementation with automatic TTL renewal
registry_provider
module-attribute
¶
registry_provider = resource_provider(
RegistryABC, init_registry
)
APIRegistry
¶
Bases: RegistryABC
Registry that stores task information via the stardag-api REST service.
This registry is stateless with respect to build_id - the build_id is passed explicitly to all methods that need it. This allows a single registry instance to be reused across multiple builds (via registry_provider).
Usage
build_id = await registry.build_start_aio(root_tasks=tasks) await registry.task_register_aio(build_id, task) await registry.task_start_aio(build_id, task)
... execute task ...¶
await registry.task_complete_aio(build_id, task) await registry.build_complete_aio(build_id)
Authentication: - API key can be provided directly or via STARDAG_API_KEY env var - JWT token from browser login (stored in registry credentials)
Configuration is loaded from the central config module (stardag.config).
Source code in stardag/registry/_api_registry.py
build_start
¶
Start a new build and return its ID.
Source code in stardag/registry/_api_registry.py
build_complete
¶
Mark a build as completed.
Source code in stardag/registry/_api_registry.py
build_fail
¶
Mark a build as failed.
Source code in stardag/registry/_api_registry.py
build_cancel
¶
Cancel a build.
Source code in stardag/registry/_api_registry.py
build_exit_early
¶
Mark a build as exited early.
Source code in stardag/registry/_api_registry.py
task_register
¶
Register a task within a build.
Source code in stardag/registry/_api_registry.py
task_start
¶
Mark a task as started.
Source code in stardag/registry/_api_registry.py
task_complete
¶
Mark a task as completed.
Source code in stardag/registry/_api_registry.py
task_fail
¶
Mark a task as failed.
Source code in stardag/registry/_api_registry.py
task_suspend
¶
Mark a task as suspended (waiting for dynamic dependencies).
Source code in stardag/registry/_api_registry.py
task_resume
¶
Mark a task as resumed (dynamic dependencies completed).
Source code in stardag/registry/_api_registry.py
task_cancel
¶
Cancel a task.
Source code in stardag/registry/_api_registry.py
task_waiting_for_lock
¶
Record that a task is waiting for a global lock.
Source code in stardag/registry/_api_registry.py
task_upload_assets
¶
Upload assets for a completed task.
Source code in stardag/registry/_api_registry.py
task_get_metadata
¶
Get metadata for a registered task.
| PARAMETER | DESCRIPTION |
|---|---|
task_id
|
The UUID of the task to get metadata for.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TaskMetadata
|
A TaskMetadata object containing task metadata. |
Source code in stardag/registry/_api_registry.py
close
¶
aclose
async
¶
build_start_aio
async
¶
Async version - start a new build and return its ID.
Source code in stardag/registry/_api_registry.py
build_complete_aio
async
¶
Async version - mark a build as completed.
Source code in stardag/registry/_api_registry.py
build_fail_aio
async
¶
Async version - mark a build as failed.
Source code in stardag/registry/_api_registry.py
build_cancel_aio
async
¶
Async version - cancel a build.
Source code in stardag/registry/_api_registry.py
build_exit_early_aio
async
¶
Async version - mark build as exited early.
Source code in stardag/registry/_api_registry.py
task_register_aio
async
¶
Async version - register a task within a build.
Source code in stardag/registry/_api_registry.py
task_start_aio
async
¶
Async version - mark a task as started.
Source code in stardag/registry/_api_registry.py
task_complete_aio
async
¶
Async version - mark a task as completed.
Source code in stardag/registry/_api_registry.py
task_fail_aio
async
¶
Async version - mark a task as failed.
Source code in stardag/registry/_api_registry.py
task_suspend_aio
async
¶
Async version - mark a task as suspended.
Source code in stardag/registry/_api_registry.py
task_resume_aio
async
¶
Async version - mark a task as resumed.
Source code in stardag/registry/_api_registry.py
task_cancel_aio
async
¶
Async version - cancel a task.
Source code in stardag/registry/_api_registry.py
task_waiting_for_lock_aio
async
¶
Async version - record that task is waiting for global lock.
Source code in stardag/registry/_api_registry.py
task_upload_assets_aio
async
¶
Async version - upload assets for a completed task.
Source code in stardag/registry/_api_registry.py
task_get_metadata_aio
async
¶
Async version of task_get_metadata.
Source code in stardag/registry/_api_registry.py
RegistryABC
¶
Abstract base class for task registries.
A registry tracks task execution within builds. Implementations must
provide at least the task_register method. All other methods have default
no-op implementations for backwards compatibility.
The registry is stateless with respect to build_id - the build_id is passed explicitly to all methods that need it. This allows a single registry instance to be reused across multiple builds.
Method naming convention:
- Build methods: build_
build_start
¶
Start a new build session.
Called at the beginning of a build. Returns a build ID.
| PARAMETER | DESCRIPTION |
|---|---|
root_tasks
|
The root tasks being built
TYPE:
|
description
|
Optional description of the build
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
UUID
|
Build ID (UUID) for the new build session. |
Source code in stardag/registry/_base.py
build_complete
¶
Mark a build as completed successfully.
| PARAMETER | DESCRIPTION |
|---|---|
build_id
|
The build UUID returned by build_start.
TYPE:
|
build_fail
¶
Mark a build as failed.
| PARAMETER | DESCRIPTION |
|---|---|
build_id
|
The build UUID returned by build_start.
TYPE:
|
error_message
|
Optional error message describing the failure.
TYPE:
|
build_cancel
¶
Cancel a build.
Called when a build is explicitly cancelled by the user.
| PARAMETER | DESCRIPTION |
|---|---|
build_id
|
The build UUID returned by build_start.
TYPE:
|
build_exit_early
¶
Mark a build as exited early.
Called when all remaining tasks are running in other builds and this build should stop waiting.
| PARAMETER | DESCRIPTION |
|---|---|
build_id
|
The build UUID returned by build_start.
TYPE:
|
reason
|
Optional reason for exiting early.
TYPE:
|
Source code in stardag/registry/_base.py
task_register
abstractmethod
¶
Register a task as pending/scheduled.
This is called when a task is about to be executed.
| PARAMETER | DESCRIPTION |
|---|---|
build_id
|
The build UUID returned by build_start.
TYPE:
|
task
|
The task to register.
TYPE:
|
Source code in stardag/registry/_base.py
task_start
¶
Mark a task as started/running.
Called immediately before a task begins execution.
| PARAMETER | DESCRIPTION |
|---|---|
build_id
|
The build UUID returned by build_start.
TYPE:
|
task
|
The task that is starting.
TYPE:
|
Source code in stardag/registry/_base.py
task_complete
¶
Mark a task as completed successfully.
Called after a task finishes execution without errors.
| PARAMETER | DESCRIPTION |
|---|---|
build_id
|
The build UUID returned by build_start.
TYPE:
|
task
|
The task that completed.
TYPE:
|
Source code in stardag/registry/_base.py
task_fail
¶
Mark a task as failed.
Called when a task raises an exception during execution.
| PARAMETER | DESCRIPTION |
|---|---|
build_id
|
The build UUID returned by build_start.
TYPE:
|
task
|
The task that failed.
TYPE:
|
error_message
|
Optional error message describing the failure.
TYPE:
|
Source code in stardag/registry/_base.py
task_suspend
¶
Mark a task as suspended waiting for dynamic dependencies.
Called when a task yields dynamic deps that are not yet complete. The task will remain suspended until its dynamic deps are built.
| PARAMETER | DESCRIPTION |
|---|---|
build_id
|
The build UUID returned by build_start.
TYPE:
|
task
|
The task that is suspended.
TYPE:
|
Source code in stardag/registry/_base.py
task_resume
¶
Mark a task as resumed after dynamic dependencies completed.
Called when a task's dynamic dependencies are complete and the task is ready to continue execution (either by resuming a suspended generator or by re-executing the task).
| PARAMETER | DESCRIPTION |
|---|---|
build_id
|
The build UUID returned by build_start.
TYPE:
|
task
|
The task that is resuming.
TYPE:
|
Source code in stardag/registry/_base.py
task_cancel
¶
Cancel a task.
Called when a task is explicitly cancelled by the user.
| PARAMETER | DESCRIPTION |
|---|---|
build_id
|
The build UUID returned by build_start.
TYPE:
|
task
|
The task to cancel.
TYPE:
|
Source code in stardag/registry/_base.py
task_waiting_for_lock
¶
Record that a task is waiting for a global lock.
Called when a task cannot acquire its lock because another build is holding it.
| PARAMETER | DESCRIPTION |
|---|---|
build_id
|
The build UUID returned by build_start.
TYPE:
|
task
|
The task waiting for the lock.
TYPE:
|
lock_owner
|
Optional identifier of who holds the lock.
TYPE:
|
Source code in stardag/registry/_base.py
task_upload_assets
¶
Upload assets for a completed task.
Called after a task completes successfully if it has registry assets.
| PARAMETER | DESCRIPTION |
|---|---|
build_id
|
The build UUID returned by build_start.
TYPE:
|
task
|
The completed task.
TYPE:
|
assets
|
List of assets to upload.
TYPE:
|
Source code in stardag/registry/_base.py
task_get_metadata
abstractmethod
¶
Get metadata for a registered task.
| PARAMETER | DESCRIPTION |
|---|---|
task_id
|
The ID of the task to get metadata for.
TYPE:
|
Returns: A TaskMetadata object containing task metadata.
Source code in stardag/registry/_base.py
build_start_aio
async
¶
Async version of build_start.
build_complete_aio
async
¶
build_fail_aio
async
¶
build_cancel_aio
async
¶
build_exit_early_aio
async
¶
task_register_aio
async
¶
task_start_aio
async
¶
task_complete_aio
async
¶
task_fail_aio
async
¶
task_suspend_aio
async
¶
task_resume_aio
async
¶
task_cancel_aio
async
¶
task_waiting_for_lock_aio
async
¶
Async version of task_waiting_for_lock.
task_upload_assets_aio
async
¶
Async version of task_upload_assets.
NoOpRegistry
¶
Bases: RegistryABC
A registry that does nothing.
Used as a default when no registry is configured.
build_start
¶
Configuration¶
config
¶
Centralized configuration for Stardag SDK.
This module provides a unified configuration system that consolidates: - Target factory settings (target roots) - API registry settings (URL, timeout, environment) - Active context (registry, workspace, environment)
Configuration is loaded from multiple sources with the following priority: 1. Environment variables (STARDAG_*) 2. Project config (.stardag/config.toml in working directory or parents) 3. User config (~/.stardag/config.toml) 4. Defaults
Usage
from stardag.config import get_config
config = get_config() print(config.api.url) print(config.target.roots)
Environment Variables (highest priority): STARDAG_PROFILE - Profile name to use (looks up in config.toml) STARDAG_REGISTRY_URL - Direct registry URL override STARDAG_WORKSPACE_ID - Direct workspace ID override STARDAG_ENVIRONMENT_ID - Direct environment ID override STARDAG_API_KEY - API key for authentication STARDAG_TARGET_ROOTS - JSON dict of target roots (override)
load_config
¶
Load configuration from all sources.
Priority (highest to lowest): 1. Environment variables (STARDAG_*) 2. Project config (.stardag/config.toml in repo) 3. User config (~/.stardag/config.toml) 4. Defaults
| PARAMETER | DESCRIPTION |
|---|---|
use_project_config
|
Whether to load .stardag/config.toml from project.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
StardagConfig
|
Fully resolved StardagConfig. |
Source code in stardag/config.py
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 | |