A simple library for running complex DAG of async tasks
Project description
async-dag
A simple library for running complex DAG of async tasks
example
import asyncio
from dataclasses import dataclass
from async_dag import TaskManager
@dataclass
class Input:
starting_number: int
async def imm() -> int:
return 1
async def inc(n: int) -> int:
return n + 1
async def to_str(n: int) -> str:
return str(n)
async def to_int(n: str, _input: Input) -> int:
return int(n)
async def inc_str(n: str) -> int:
return int(n) + 1
async def inc_max(a: int, b: int) -> int:
return max(a, b) + 1
with build_dag(Input) as tm:
starting_node = tm.add_node(imm)
inc_1 = tm.add_node(inc, starting_node)
str_node = tm.add_node(to_str, starting_node)
str_to_int_node = tm.add_node(to_int, str_node)
int_node = tm.add_node(inc_str, str_node)
inc_2 = tm.add_node(inc, int_node)
end_1 = tm.add_node(inc_max, inc_2, inc_1)
end_2 = tm.add_node(inc_max, inc_1, starting_node)
end_3 = tm.add_node(inc_max, str_to_int_node, starting_node)
result_1 = await tm.invoke(Input(0))
result_2 = await tm.invoke(Input(999))
assert end_1.extract_result(result_1) == 3
assert end_2.extract_result(result_1) == 2
assert end_3.extract_result(result_1) == 1
assert end_1.extract_result(result_2) == 1002
assert end_2.extract_result(result_2) == 1001
assert end_3.extract_result(result_2) == 1000
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
async_dag-0.1.0.tar.gz
(15.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file async_dag-0.1.0.tar.gz.
File metadata
- Download URL: async_dag-0.1.0.tar.gz
- Upload date:
- Size: 15.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.6.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f644b78a3bc066daf07c4c2acf222e52ca67dcd4c30d6f88cf3acbf42328c7e4
|
|
| MD5 |
7a6ae21e4f80c14542ae7cbff47496cf
|
|
| BLAKE2b-256 |
de46dcb2674a930354aeb85cf48f13a59fa2068283b9c7d8217c425f5886bdbe
|
File details
Details for the file async_dag-0.1.0-py3-none-any.whl.
File metadata
- Download URL: async_dag-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.6.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc539392a87f40c474af2f8b33d88a1e4ee7be3966574cbe80bed6ae2306bfc1
|
|
| MD5 |
80a98f9dd776a89e9768879bb483295d
|
|
| BLAKE2b-256 |
4982b71148aac6156c00e005e71f7a7c02c3576c7711da7e34a57c45f3b2f2ec
|