Skip to main content

Lightweight asyncio task tracking as call tree and DAG

Project description

aionode

Lightweight asyncio task tracking as call tree and DAG.

Installation

pip install aionode

Quick Start

import asyncio
import aionode

async def fetch_data() -> list[int]:
    await asyncio.sleep(1)
    return list(range(100))

async def process(data: list[int]) -> int:
    await asyncio.sleep(0.5)
    return sum(data)

async def pipeline() -> None:
    async with asyncio.TaskGroup() as tg:
        fetch = tg.create_task(aionode.node(fetch_data)(), name="fetch")
        tg.create_task(aionode.node(process)(aionode.resolve(fetch)), name="process")

async def main() -> None:
    root = asyncio.create_task(aionode.node(pipeline)(), name="pipeline")
    await root
    for info in aionode.walk_dag():
        print(f"{info.name}: {info.status} ({info.duration():.2f}s)")

asyncio.run(main())

Core Concepts

node(func, wait_for=[], track=True, auto_progress=True)

Wraps an async function as a DAG node. Use resolve() to pass awaitables as arguments — they are gathered concurrently before the function is called. Sync functions must be wrapped with make_async first.

# Async function — pass upstream tasks with resolve()
fetch = tg.create_task(aionode.node(fetch_data)(), name="fetch")
process_task = tg.create_task(aionode.node(process)(aionode.resolve(fetch)), name="process")

# Sync function — wrap with make_async first
summarize = tg.create_task(
    aionode.node(aionode.make_async(my_sync_fn))(aionode.resolve(process_task)),
    name="summarize",
)

# Side-only dependency (no value passed): use wait_for
task_b = tg.create_task(aionode.node(cleanup, wait_for=[fetch])(), name="cleanup")

resolve(awaitable)

Marks an awaitable to be resolved before being passed as an argument to node(). This preserves type information — the type checker sees resolve(task: Task[T]) as returning T.

result = await aionode.node(process)(aionode.resolve(upstream_task))

walk_tree / walk_dag

Iterate over tracked tasks after they have been created.

# DFS pre-order through the call tree (parent → children)
for info in aionode.walk_tree():
    print(info.name, info.status)

# Topological order over the DAG (deps → dependents)
for info in aionode.walk_dag():
    print(info.name, info.status)

Both accept an optional root argument (an asyncio.Task or task id). Passing None (the default) includes all tasks in the current event loop.

Task Inspection

task_id = await aionode.get_task_id(asyncio_task)
info = aionode.get_task_info(task_id)

info.status        # TaskStatus: WAITING, RUNNING, DONE, FAILED, CANCELLED
info.duration()    # Elapsed seconds
info.name          # Task name
info.deps          # Upstream dependency IDs
info.dependents    # Downstream dependent IDs
info.logs          # Accumulated log output

await aionode.log("processing record 42")  # Append to current task's logs

# Get TaskInfo for the currently running tracked task
info = aionode.current_task_info()

API Reference

Function Description
node(func, wait_for, track, auto_progress) Wrap an async function as a DAG node
resolve(awaitable) Mark an awaitable to be resolved as a node argument
get_task_id(task, timeout) Get the task ID for an asyncio.Task
get_task_info(task_id) Get TaskInfo by ID
current_task_info() Get TaskInfo for the currently running tracked task
remove_task(task_id) Remove a task and its descendants
log(value, end) Append to the current task's logs
make_async(func) Run a sync function in a thread
make_async_generator(gen) Async iterate a sync iterator via threads
walk_tree(root) DFS pre-order through the call tree
walk_dag(root) Topological order over the DAG

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aionode-0.2.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aionode-0.2.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file aionode-0.2.0.tar.gz.

File metadata

  • Download URL: aionode-0.2.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for aionode-0.2.0.tar.gz
Algorithm Hash digest
SHA256 71fc1de59b2c5d7aef3ee2f1b78ebd5e5dda2ab8952eae6bb610a8eeb8b344e5
MD5 d3ae30ed36aa984068157a036f634f3e
BLAKE2b-256 01805eb83edf0fa091dc3b645c450671b10285893c7c5c52a36cd91c2d953582

See more details on using hashes here.

Provenance

The following attestation bundles were made for aionode-0.2.0.tar.gz:

Publisher: publish.yml on MatteoDep/aionode

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aionode-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: aionode-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for aionode-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e63be66f6594f11fb3d916c8d6c9f19e5241a4781b520c3d27826a8b0af62404
MD5 4b4d2e792fe75488393575297d0a3684
BLAKE2b-256 cba38f7987471cbd97cc641250293827e7c99518deb25d391ed71655b8539221

See more details on using hashes here.

Provenance

The following attestation bundles were made for aionode-0.2.0-py3-none-any.whl:

Publisher: publish.yml on MatteoDep/aionode

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page