Skip to main content

kahn-queue (Python)

PyPI

Getting started

  • Python: 3.10+ recommended (venv + requirements-dev.txt; no version pinned in-repo).
  • Tests: make test-python, or cd python, create .venv, install requirements-dev.txt, then pytest.
  • Imports: Examples assume src is on PYTHONPATH (the test suite does this via tests/conftest.py). From the repo: PYTHONPATH=src or pip install -e . once packaging is configured.

Pieces

Piece Role
Dag / Dag.builder() Immutable DAG: add, connect, build().
KahnScheduler run(), signal_complete, signal_failed; is_finished (property); get_result() → DagResult.
DagResult completed, failed, pruned — each a frozenset of node ids.
KahnQueue / DefaultKahnQueue / ConcurrentKahnQueue DefaultKahnQueue when queue is omitted; pass ConcurrentKahnQueue(dag) for concurrent pop / prune.
IllegalGraphException Invalid graphs (self-loop, cycle at build(), etc.).
NodeProgressTracker Optional per-node progress in [0, 1] (tracker module); not required for scheduling.

Examples

Single threaded queue

from dag import Dag
from scheduler import KahnScheduler

b = Dag.builder()
root = b.add("lint")
mid = b.add("compile")
leaf = b.add("test")
b.connect(root, mid).connect(mid, leaf)
dag = b.build()


def execute_node(node_id: int, sched: KahnScheduler[str]) -> None:
    try:
        run_step(dag[node_id])  # your step
        sched.signal_complete(node_id)
    except Exception:
        sched.signal_failed(node_id)

sched = KahnScheduler(dag, execute_node)
sched.run()

Concurrent queue

from dag import Dag
from kahnQueue.concurrent_kahn_queue import ConcurrentKahnQueue
from scheduler import KahnScheduler

b = Dag.builder()
a = b.add("a")
c = b.add("c")
jn = b.add("join")
b.connect(a, jn).connect(c, jn)
dag = b.build()


def execute_node(node_id: int, sched: KahnScheduler[str]) -> None:
    ...

sched = KahnScheduler(dag, execute_node, queue=ConcurrentKahnQueue(dag))
sched.run()

Result

result = sched.get_result()
# result.completed, result.failed, result.pruned — frozensets of ids
done = sched.is_finished

Manual KahnQueue

from dag import Dag
from kahnQueue.default_kahn_queue import DefaultKahnQueue

b = Dag.builder()
lint = b.add("lint")
compile = b.add("compile")
test = b.add("test")
b.connect(lint, compile).connect(compile, test)
dag = b.build()

q = DefaultKahnQueue(dag)

ready = list(q.peek())

while ready:
    id_ = ready.pop(0)

    # do work for `id_` (e.g. run_step(dag[id_]))

    promoted = q.pop(id_)
    ready.extend(promoted)

    # If a node fails, you can prune it (and its descendants):
    # q.prune(id_)

Metadata

Release files for kahn-queue 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kahn-queue 1.0.2
File Size Uploaded Provenance Actions
kahn_queue-1.0.2.tar.gz 13.5 kB Without provenance Details for kahn_queue-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for kahn-queue 1.0.2
File Interpreter ABI Platform Actions
kahn_queue-1.0.2-py3-none-any.whl Python 3 none any Details for kahn_queue-1.0.2-py3-none-any.whl

Total release size: 24.3 kB

Release files / kahn_queue-1.0.2.tar.gz

Download URL kahn_queue-1.0.2.tar.gz
Size 13.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f7a252739e594fb515fb05046d4e4084431e537ccf753cef60f8f7077593887f
BLAKE2b-256 checksum
How to use checksums
73483ef3299c523eff9d2932ee4abda1692364bb45881f2ec25abd41e83a8419
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / kahn_queue-1.0.2-py3-none-any.whl

Download URL kahn_queue-1.0.2-py3-none-any.whl
Size 10.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
41aac2b280b0e392b3711b20c9cd0a227a8cd70b96950040262a5bf888f63d12
BLAKE2b-256 checksum
How to use checksums
db92133554a029d5ab6cb993ffb8bb3df3f4d0aa76a4b7c4f60cfd3db02be047
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Security for kahn-queue 1.0.2

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page