orchestral
Orchestrate and execute shell commands, async coroutines, and sync Python functions in structured, concurrent workflows.
| Package | orchestral |
|---|---|
| Version | 0.2.0 |
| Download | https://pypi.org/project/orchestral/ |
| Source | https://github.com/adalundhe/orchestral |
| Keywords | async, tasks, workflow, runner, graph, shell, jobs |
Features
- Unified task orchestration: Mix shell commands (
add_command),async defcoroutines, and synchronous Python callables (add_task) in the same workflow. - Sequential groups, concurrent steps: Groups execute strictly in order; all steps inside a group execute concurrently.
- Streaming batch results: Consume each group's results as it completes using
async for batch in orch:. - Fail-fast & error capture: Run to completion by default or enable
fail_fast=Trueto cancel in-flight siblings immediately and stop subsequent groups on the first failure. - Timeouts at every level: Enforce deadlines on individual steps or the entire workflow using numbers (seconds) or duration strings (
"500ms","5s","1m30s"). - Safe process & resource lifecycle: Automatically terminates and reaps subprocesses (including child process groups on POSIX), shuts down executors cleanly, and supports
async with,stop(),shutdown(), andabort(). - Scheduled / repeating steps: Repeat individual steps on an interval with bounded history retention (
COUNT,AGE, orCOUNT_AND_AGE).
Installation
Requires Python 3.11 or newer.
pip install orchestral
Or with uv:
uv add orchestral
Quick Start
import asyncio
from taskex import Env
from orchestral import Orchestral, WorkflowStatus
async def fetch_greeting(name: str) -> str:
await asyncio.sleep(0.05)
return f"Hello, {name}!"
def compute_checksum(text: str) -> int:
return sum(ord(ch) for ch in text)
async def main() -> None:
config = Env(MERCURY_SYNC_EXECUTOR_TYPE="thread")
async with Orchestral(config=config) as orch:
with orch as workflow:
# Group 1: runs concurrently
prepare = workflow.group()
prepare.add_command("echo", "starting pipeline", alias="banner")
prepare.add_task(fetch_greeting, "orchestral", alias="greet")
# Group 2: starts only after Group 1 finishes
analyze = workflow.group()
analyze.add_task(compute_checksum, "orchestral", alias="checksum")
await orch.run(wait=True, fail_fast=True, timeout="30s")
print("Status:", orch.status)
print("Elapsed:", f"{orch.elapsed:.3f}s")
for task_name, runs in orch.results.items():
for run_id, result in runs.items():
print(task_name, run_id, result.status, result.result)
asyncio.run(main())
Common Patterns
Non-blocking runs & streaming batch results
async with Orchestral() as orch:
with orch as workflow:
g1 = workflow.group()
g1.add_command("ls", alias="list_files")
g1.add_command("pwd", alias="working_dir")
g2 = workflow.group()
g2.add_command("echo", "done", alias="finish")
await orch.run(wait=False)
async for batch in orch:
print("Completed group:", [(r.task_name, r.status.value) for r in batch])
Explicit lifecycle management
If you prefer not to use async with, always call await orch.shutdown() (or synchronous orch.abort() in emergency teardown) when finished:
orch = Orchestral()
try:
with orch as workflow:
group = workflow.group()
group.add_command("echo", "hello")
await orch.run(wait=True)
finally:
await orch.shutdown()
Error handling & fail_fast
fail_fast=False(default): individual failures are recorded on theirTaskRun/ShellProcessentries inorch.resultswithstatus == RunStatus.FAILED, while remaining steps and groups continue to run.fail_fast=True: the first failed step immediately cancels remaining in-flight siblings in the current group, skips subsequent groups, records the completed results from the failing group, setsorch.status = WorkflowStatus.FAILED, and populatesorch.errorwith anOrchestralTaskFailure(andorch.tracewith the traceback).
Executor configuration
Synchronous functions passed to add_task() run in either a ProcessPoolExecutor (default) or a ThreadPoolExecutor, configured via taskex.Env:
from taskex import Env
from orchestral import Orchestral
# Use threads for closures, lambdas, bound methods, or I/O-bound sync code
orch = Orchestral(
config=Env(
MERCURY_SYNC_EXECUTOR_TYPE="thread",
MERCURY_SYNC_TASK_RUNNER_MAX_THREADS=4,
)
)
Note: When using the default
"process"executor, sync callables and their arguments must be picklable (e.g. top-level module functions). Pure shell and async workflows never spawn an executor.
Documentation
Detailed guides and API reference live in docs/:
- Documentation Index
- Getting Started
- Execution Model & Configuration
- Error Handling, Timeouts & Lifecycle
- API Reference
Runnable examples are available in examples/:
Development & Testing
uv venv --python 3.13
uv pip install -r requirements.txt pytest pytest-asyncio
PYTHONPATH=. .venv/bin/pytest -v tests/
License
MIT — see LICENSE.
Metadata
Release files for orchestral 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| orchestral-0.2.0.tar.gz | 25.8 kB | Without provenance | Details for orchestral-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| orchestral-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for orchestral-0.2.0-py3-none-any.whl |
Total release size: 44.1 kB
Release files / orchestral-0.2.0.tar.gz
| Download URL | orchestral-0.2.0.tar.gz |
|---|---|
| Size | 25.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
964826ddba5566df5e198ddfd9cb8d42aad9f5223baaecc2d1e8bdb7ad516c97
|
|
BLAKE2b-256 checksum How to use checksums |
9662d314fd438176a54f5e931a48ef37c7793344861e0039b74ce23ef659b12d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / orchestral-0.2.0-py3-none-any.whl
| Download URL | orchestral-0.2.0-py3-none-any.whl |
|---|---|
| Size | 18.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ee87f8e2715dd756e276acb23c3b575493c25e0c766ab27bd31e082d7a41aee3
|
|
BLAKE2b-256 checksum How to use checksums |
154532549be3db5dbea9e7a02d7071a250f4da5df516fb4bf42981200527c9eb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for orchestral 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.